Ejemplo n.º 1
0
        void WatchConncting()
        {
            try
            {
                //循环监听客户端的连接请求。
                while (isWatch)
                {
                    //2.4开始监听,返回了一个通信套接字
                    Socket sockMsg = sokWatch.Accept();
                    //2.5 创建通信管理类
                    MsgConnection conn = new MsgConnection(sockMsg, ShowMsg, RemoveClient);

                    //将当前连接成功的【与客户端通信的套接字】的标识保存起来,并显示到列表中
                    //将远程客户端的 ip 和 端口 字符串 存入列表
                    listOnline.Items.Add(sockMsg.RemoteEndPoint.ToString());
                    //将服务器端的通信套接字存入字典集合。
                    dictConn.Add(sockMsg.RemoteEndPoint.ToString(), conn);
                    ShowMsg("有客户端连接了!");
                }
            }
            catch (Exception ex)
            {
                ShowMsg("异常" + ex);
            }
        }
Ejemplo n.º 2
0
        public void Send(NecPacket packet)
        {
            switch (packet.ServerType)
            {
            case ServerType.Area:
                AreaConnection.Send(packet);
                break;

            case ServerType.Msg:
                MsgConnection.Send(packet);
                break;

            case ServerType.Auth:
                AuthConnection.Send(packet);
                break;

            default:
                Logger.Error(this, "Invalid ServerType");
                break;
            }
        }