private void TcpSock_OnClientConnect(BaseServerSocket sender, Socket s) { var client = new InternalSyncIOConnectedClient(s, _packager); client.SetID(_guidGenerator()); client.BeginReceve(ReceveHandler); client.Send(cl => { Clients.Add(cl); client.OnDisconnect += (c, err) => Clients.Remove(c); OnClientConnect?.Invoke(this, cl);//Trigger event after handshake packet has been sent. }, new HandshakePacket(client.ID, true)); }
/// <summary> /// Listens on a new port. /// </summary> /// <param name="port">Port to listen</param> /// <returns>The open socket on success, else null.</returns> public SyncIOSocket ListenTCP(int port) { var baseSock = new BaseServerSocket(Protocal); baseSock.OnClientConnect += TcpSock_OnClientConnect; if (!baseSock.BeginAccept(port)) { return(null); } OpenSockets.Add(baseSock); baseSock.OnClose += (s, err) => { OpenSockets.Remove(s); }; baseSock.UdpDataReceved += HandleUDPData; return(baseSock); }