added on connect functionality

This commit is contained in:
waltem01 2022-07-01 07:40:23 +02:00
parent a054b0137c
commit 755f7a3639

View File

@ -13,6 +13,7 @@ public static class Connection {
public static string ipAddress;
private static int listeners = 0;
public static Action<Socket> disconnectMethod;
public static Action<Socket> connectMethod;
public static List<MessageEvent> messageEvents;
public static void Initialize(int _port=3000) {
@ -21,6 +22,7 @@ public static class Connection {
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";
@ -120,6 +122,7 @@ public static class Connection {
other.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), other);
if (self == null)
self = other;
connectMethod.Invoke(other);
}
// Handle sending messages