Beispiel #1
0
        public void Send(string remote, byte[] data)
        {
            CSConnection connection = null;

            if (!map_remote2Connection.TryGetValue(remote, out connection))
            {
                NetDebug.Log("[TCPServer] try send, but the remote:{0} is null.", remote);
                return;
            }
            connection.Send(data);
        }
Beispiel #2
0
        private void TryRemoveConnection(string remote)
        {
            lock (map_remote2Connection)
            {
                CSConnection connection = null;
                if (map_remote2Connection.TryGetValue(remote, out connection))
                {
                    map_remote2Connection.Remove(remote);

                    ConnectionMessage message = new ConnectionMessage(remote);
                    onConnectionDropped.SafeInvoke(message);
                }
            }
        }
Beispiel #3
0
        private void TryInitConnection(Socket socket)
        {
            if (null == socket)
            {
                return;
            }

            lock (map_remote2Connection)
            {
                string remote = socket.RemoteEndPoint.ToString();
                if (!map_remote2Connection.ContainsKey(remote))
                {
                    CSConnection connection = new CSConnection(socket);
                    connection.onReceiveCallback += OnConnectionRecevie;
                    connection.onClosedCallback  += OnConnectionClosed;
                    map_remote2Connection.Add(remote, connection);
                }
            }
        }