コード例 #1
0
 private HandleResult OnClose(IServer sender, IntPtr connId, SocketOperation socketOperation, int errorCode)
 {
     if (errorCode == 0)
     {
         AddLog($"客户端断开连接,连接ID:{connId}");
     }
     else
     {
         AddLog($"客户端连接异常, ,连接ID:{connId},错误代码{errorCode}");
     }
     ChkLbClients.BeginInvoke((Action)(() => { ChkLbClients.Items.Remove(connId.ToString()); }));
     return(HandleResult.Ok);
 }
コード例 #2
0
        private HandleResult OnAccept(IServer sender, IntPtr connId, IntPtr client)
        {
            // 获取客户端地址
            if (!sender.GetRemoteAddress(connId, out var ip, out var port))
            {
                return(HandleResult.Error);
            }

            string connIdStr = connId.ToString();

            AddLog($"接受客户端连接请求,连接ID({connIdStr}), ip: {ip}, port: {port}");

            if (!ChkLbClients.Items.Contains(connIdStr))
            {
                ChkLbClients.BeginInvoke((Action)(() => { ChkLbClients.Items.Add(connIdStr); }));
            }

            return(HandleResult.Ok);
        }