Esempio n. 1
0
        HandleResult OnAccept(IntPtr connId, IntPtr pClient)
        {
            // 客户进入了


            // 获取客户端ip和端口
            string ip   = string.Empty;
            ushort port = 0;

            if (server.GetRemoteAddress(connId, ref ip, ref port))
            {
                AddMsg(string.Format(" > [{0},OnAccept] -> PASS({1}:{2})", connId, ip.ToString(), port));
            }
            else
            {
                AddMsg(string.Format(" > [{0},OnAccept] -> Server_GetClientAddress() Error", connId));
            }


            // 设置附加数据
            ClientInfo ci = new ClientInfo();

            ci.ConnId    = connId;
            ci.IpAddress = ip;
            ci.Port      = port;
            if (server.SetConnectionExtra(connId, ci) == false)
            {
                AddMsg(string.Format(" > [{0},OnAccept] -> SetConnectionExtra fail", connId));
            }

            return(HandleResult.Ok);
        }