GodotTicTacToe/scripts/net/Client.cs
2017-11-25 15:30:34 +02:00

42 lines
1.2 KiB
C#

using Godot;
using Network.PacketHandling;
using Network.PacketHandling.Packets;
using System;
namespace Network {
public class Client : Peer {
private PacketPeerUDP PacketPeer;
private Connection ServerConn;
private float Timer = 0;
public Client(PacketPeerUDP packetPeer) : base(packetPeer, false) {
PacketPeer = packetPeer;
}
public override void Initialize(string address, int port) {
GD.print("Start client.");
ServerConn = new Connection(address, port);
ServerConn.Name = "Server";
ConnectionList.AddConnection(ServerConn);
StartListening(port, "*");
}
public override void Process(float delta) {
Timer += delta;
if (Timer > 10) {
Timer = 0;
TextMessagePkt Pkt = new TextMessagePkt();
Pkt.Text = "Hello, Server!";
PacketDistributor.AddReliableForAll(Pkt);
}
}
public override void Connected(Connection conn) {
GD.print("Connected to " + conn.Name + " at " + conn.Address + ":" + conn.Port);
PacketDistributor.AddHandler(ServerConn);
}
}
}