Пример #1
0
        public void Disconnect()
        {
            if (socket != null)
            {
                socket.Dispose();
                socket = null;
            }

            if (Disconnected != null)
                Disconnected(this);
        }
Пример #2
0
        private void AcceptCallback(IAsyncResult asyncResult)
        {
            lock (this)
            {
                if (!IsListening)
                    return;

                Socket clientHandle = nativeSocket.EndAccept(asyncResult);
                var newConnectedClient = new TcpSocket(clientHandle);
                TriggerClientConnectedEvent(newConnectedClient);
                newConnectedClient.WaitForData();
                nativeSocket.BeginAccept(AcceptCallback, null);
            }
        }
Пример #3
0
 private void TriggerClientConnectedEvent(TcpSocket newConnectedClient)
 {
     if (ClientConnected != null)
         ClientConnected(newConnectedClient);
 }
Пример #4
0
 public TcpNetworkingClient(IPEndPoint serverAddress)
 {
     this.serverAddress = serverAddress;
     socket = new TcpSocket();
     socket.DataReceived += OnDataReceived;
 }