mirror of
https://gitlab1.ptb.de/waltem01/csharpsocketserver
synced 2024-02-04 23:19:43 +00:00
listening bugfix
This commit is contained in:
parent
a7dd4f610b
commit
98e34ab248
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user