mirror of
https://gitlab1.ptb.de/waltem01/csharpsocketserver
synced 2024-02-04 23:19:43 +00:00
Merge branch 'master' of https://gitlab1.ptb.de/waltem01/csharpsocketserver
This commit is contained in:
commit
b6a0e4e9a5
17
SocketLib.cs
17
SocketLib.cs
|
@ -21,8 +21,6 @@ public static class Connection {
|
|||
port = _port;
|
||||
buffer = new byte[1024];
|
||||
messageEvents = new List<MessageEvent>();
|
||||
disconnectMethod = new Action<Socket>((other)=>{});
|
||||
connectMethod = new Action<Socket>((other)=>{});
|
||||
|
||||
// Get computers' ipv4 address
|
||||
ipAddress = "127.0.0.1";
|
||||
|
@ -72,6 +70,9 @@ public static class Connection {
|
|||
self.Connect(new IPEndPoint(IPAddress.Parse(ipAddr), _port));
|
||||
|
||||
self.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), self);
|
||||
|
||||
if (connectMethod != null)
|
||||
connectMethod.Invoke(self);
|
||||
}
|
||||
|
||||
public static void ClientListen() {
|
||||
|
@ -110,12 +111,9 @@ public static class Connection {
|
|||
// Begin listening for more messages
|
||||
other.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), other);
|
||||
} catch (Exception) {
|
||||
// Potentially detected Disconnect
|
||||
if (other.Connected) {
|
||||
// Close client connection
|
||||
disconnectMethod.Invoke(other);
|
||||
other.Close();
|
||||
}
|
||||
// Close client connection
|
||||
disconnectMethod.Invoke(other);
|
||||
other.Close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,7 +125,8 @@ public static class Connection {
|
|||
other.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), other);
|
||||
if (self == null)
|
||||
self = other;
|
||||
connectMethod.Invoke(other);
|
||||
if (connectMethod != null)
|
||||
connectMethod.Invoke(other);
|
||||
}
|
||||
|
||||
// Handle sending messages
|
||||
|
|
Loading…
Reference in New Issue
Block a user