GodotTicTacToe/scripts/Server.cs

31 lines
935 B
C#
Raw Normal View History

2017-11-21 18:33:48 +01:00
using Godot;
using System.Threading;
public class Server : Peer {
private static PacketPeerUDP PacketPeer;
public Server(PacketPeerUDP packetPeer) : base(packetPeer) {
PacketPeer = packetPeer;
}
public override void Initialize(string address, int port) {
PacketPeer.Listen(port, address);
ThreadStart childref = new ThreadStart(ListenerThread);
System.Threading.Thread thread = new System.Threading.Thread(childref);
thread.Start();
GD.print("Server initialization finished.");
}
public override void Update(float delta) {
}
public static void ListenerThread() {
GD.print("Started Listener Thread.");
while (true) {
PacketPeer.Wait();
GD.print("Received stuff from " + PacketPeer.GetPacketIp() + " : " + PacketPeer.GetPacketPort() + " :");
GD.print(PacketPeer.GetPacket()[0]);
}
}
}