listening bugfix

This commit is contained in:
waltem01 2022-06-30 12:33:31 +02:00
parent a7dd4f610b
commit 98e34ab248

View File

@ -69,11 +69,11 @@ public static class Connection {
public static void ClientListen() {
// Create a new socket server and listen for connections
Socket self = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
self.Bind(new IPEndPoint(IPAddress.Parse(ipAddress), port));
self.Listen(1);
Socket own = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
own.Bind(new IPEndPoint(IPAddress.Parse(ipAddress), port));
own.Listen(1);
// Accept any client, stop listening after first client is connected and return client
self.BeginAccept(new AsyncCallback(AcceptCallback), self);
own.BeginAccept(new AsyncCallback(AcceptCallback), own);
}
// End off the message send-callback
@ -114,6 +114,8 @@ public static class Connection {
Socket other = own.EndAccept(AR);
listeners--;
other.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), other);
if (self == null)
self = other;
}
// Handle sending messages