예제 #1
0
        private HandleResult _server_OnClose(IntPtr connId)
        {
            String connectIp = "";
            ushort connectPort = 0;
            if (_server.GetRemoteAddress(connId, ref connectIp, ref connectPort))
            {
                ClientInformation ci = new ClientInformation()
                {
                    ConnId = connId,
                    IpAddress = connectIp,
                    Port = connectPort
                };
                UpdateSourceDic(ci, ClientConnectStateEnum.Close);
                UpdateClientListInvoke();
                AddMessageToControlInvoke(richTextBoxReceiver, String.Format("|{0}| close connection",ci.GetFullAddress() ));
            }
            else
            {

            }
            return HandleResult.Ok;
        }
예제 #2
0
 private void UpdateSourceDic(ClientInformation ci, ClientConnectStateEnum connectState)
 {
     String key = String.Format("{0}:{1}", ci.IpAddress, ci.Port);
     if (connectState == ClientConnectStateEnum.Connect)
     {
         if (!_dicClient.ContainsKey(key))
         {
             _dicClient.Add(key,ci);
         }
     }
     else
     {
         if (_dicClient.ContainsKey(key))
         {
             _dicClient.Remove(key);
         }
     }
 }
예제 #3
0
        private HandleResult _server_OnAccept(IntPtr connId, IntPtr pClient)
        {
            String connectIp = "";
            ushort connectPort = 0;
            ClientInformation ci = null;
            if (_server.GetRemoteAddress(connId, ref connectIp, ref connectPort))
            {
                ci = new ClientInformation()
                {
                    ConnId = connId,
                    IpAddress = connectIp,
                    Port = connectPort
                };
                UpdateSourceDic(ci, ClientConnectStateEnum.Connect);
                UpdateClientListInvoke();
                AddMessageToControlInvoke(richTextBoxReceiver,String.Format("|{0}| connected",ci.GetFullAddress()));
            }
            else
            {

            }
            if (_server.SetConnectionExtra(connId, ci))
            {
                AddMessageToControlInvoke(richTextBoxReceiver, String.Format("|{0}| setconnect success", ci.GetFullAddress()));
            }
            return HandleResult.Ok;
        }
예제 #4
0
 private void Send(ClientInformation ci, String message)
 {
     byte[] bytes = Encoding.Unicode.GetBytes(message);
     Boolean result= _server.Send(ci.ConnId, bytes, 0, bytes.Length);
     if (result)
     {
         AddMessageToControlInvoke(richTextBoxSender,String.Format("->|{0}|\r\n{1}\r\n",ci.GetFullAddress(),message));
         SetTextInvoke(textBoxSender, "", false);
     }
 }