Пример #1
0
        private void tcpSocketListener_NewClientAccepted(object sender, System.Net.Sockets.Socket client, object state)
        {
            if (this.ServerConfig.SocketMode == SocketMode.Tcp)
            {
                if (this.ServerConfig.ControlMode == ControlMode.Loop ||
                    this.ServerConfig.ControlMode == ControlMode.Self ||
                    this.ServerConfig.ControlMode == ControlMode.Parallel)
                {
                    if (ServerConfig.CheckSameSocketSession)
                    {
                        string[] ipInfo        = client.RemoteEndPoint.ToString().Split(':');
                        IChannel socketSession = ChannelManager.GetChannel(ipInfo[0], CommunicateType.NET);
                        if (socketSession != null)
                        {
                            RemoveTcpSocketSession((ISocketSession)socketSession);
                        }
                    }
                }

                AddTcpSocketSession(client);
            }
            else if (this.ServerConfig.SocketMode == SocketMode.Udp)
            {
                object[]       arr           = (object[])state;
                ISocketSession socketSession = new UdpSocketSession(client, (IPEndPoint)arr[1], null);
                Logger.Info(false, String.Format("远程UDP接收到数据>>{0}:{1}", socketSession.RemoteIP, socketSession.RemotePort));

                IList <IRequestInfo> ris = new List <IRequestInfo>();
                ris.Add(new RequestInfo(socketSession.Key, (byte[])arr[0], socketSession));
                IReceivePackage rp = new ReceivePackage(socketSession.RemoteIP, socketSession.RemotePort, ris);
                socketChannel_SocketReceiveData(socketSession, socketSession, rp);
            }
        }
Пример #2
0
        private void tcpSocketListener_NewClientAccepted(object sender, System.Net.Sockets.Socket client, object state)
        {
            if (this.Config.SocketMode == SocketMode.Tcp)
            {
                if (this.Config.ControlMode == ControlMode.Loop ||
                    this.Config.ControlMode == ControlMode.Self ||
                    this.Config.ControlMode == ControlMode.Parallel)
                {
                    if (Config.IsCheckSameSocketSession)
                    {
                        string[] ipInfo        = client.RemoteEndPoint.ToString().Split(':');
                        IChannel socketSession = ChannelManager.GetChannel(ipInfo[0], CommunicateType.NET);
                        if (socketSession != null)
                        {
                            RemoveTcpSocketSession((ISocketSession)socketSession);
                        }
                    }
                }

                AddTcpSocketSession(client);
            }
            else if (this.Config.SocketMode == SocketMode.Udp)
            {
                object[]       arr           = (object[])state;
                ISocketSession socketSession = new UdpSocketSession(client, (IPEndPoint)arr[1], null);
                socketChannel_SocketReceiveData(socketSession, socketSession, (byte[])arr[0]);
            }
        }