コード例 #1
0
        HandleResult OnAccept(IServer sender, 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 clientInfo = new ClientInfo();

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

            return(HandleResult.Ok);
        }
コード例 #2
0
ファイル: frmServer.cs プロジェクト: zxk69809/HP-Socket
        HandleResult OnAccept(IntPtr connId, IntPtr pClient)
        {
            // 客户进入了
            if (clientCount == 0)
            {
                lock (title)
                {
                    if (clientCount == 0)
                    {
                        Reset(false);
                    }
                }
            }

            Interlocked.Increment(ref clientCount);

            // 获取客户端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));
            }

            return(HandleResult.Ok);
        }
コード例 #3
0
ファイル: frmServer.cs プロジェクト: l0vekobe0824/HP-Socket
        HandleResult OnAccept(uint dwConnID, IntPtr pClient)
        {
            // 客户进入了


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

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


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

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

            return(HandleResult.Ok);
        }
コード例 #4
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(" > [连接客户端ID:{0}] -> IP地址({1}:{2})", connId, ip.ToString(), port));
            }
            else
            {
                AddMsg(string.Format(" > [连接客户端ID:{0}] -> Server_GetClientAddress() Error", connId));
            }


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

            clientInfo.ConnId    = connId;
            clientInfo.IpAddress = ip;
            clientInfo.Port      = port;

            htCI.Add(connId, clientInfo);
            if (extra.Set(connId, clientInfo) == false)
            {
                AddMsg(string.Format(" > [连接客户端ID:{0}] -> 设置连接附加信息异常", connId));
            }
            else
            {
                //刷新datagridview数据
                DataTable dt = new DataTable();
                dt.Columns.Add("connid");
                dt.Columns.Add("IP");
                dt.Columns.Add("prot");

                ClientInfo ci = new ClientInfo();
                foreach (var item in htCI.Values)
                {
                    ci = (ClientInfo)item;
                    DataRow dr = dt.NewRow();
                    dr["connid"] = ci.ConnId.ToString();
                    dr["IP"]     = ci.IpAddress.ToString();
                    dr["prot"]   = ci.Port.ToString();
                    dt.Rows.Add(dr);
                }

                fnUpdateGridView(dt);
            }

            return(HandleResult.Ok);
        }
コード例 #5
0
ファイル: frmServer.cs プロジェクト: l0vekobe0824/HP-Socket
        HandleResult OnAccept(uint dwConnID, IntPtr pClient)
        {
            // 客户进入了
            if (clientCount == 0)
            {
                lock (title)
                {
                    if (clientCount == 0)
                    {
                        Reset(false);
                    }
                }
            }

            Interlocked.Increment(ref clientCount);

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

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


            // 设置附加数据

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

            return(HandleResult.Ok);
        }
コード例 #6
0
        HandleResult OnAccept(IntPtr connId, IntPtr pClient)
        {
            string ip   = string.Empty;
            ushort port = 0;

            if (!m_tcpserver.GetRemoteAddress(connId, ref ip, ref port))
            {
                return(HandleResult.Error);
            }
            lock (m_LockObject)
            {
                SocketEvent e = new SocketEvent();
                e.connId = connId;
                e.type   = SocketEvent.SOCKETEVENT_TYPE.ONACCEPT;

                m_Queue.Enqueue(e);
            }

            return(HandleResult.Ok);
        }