Inheritance: System.Net.Sockets.SocketAsyncEventArgs
Exemplo n.º 1
0
 public NSocketSAEAItem(string uid = "", Socket socket = null)
 {
     this.UID = uid;
     ReceiveSAEA = new NSocketSocketAsyncEventArgs("receive") { UID = uid, UserToken = socket };
     SendSAEA = new NSocketSocketAsyncEventArgs("send") { UID = uid, UserToken = socket };
     this.LastMessageTime = DateTime.Now;
 }
Exemplo n.º 2
0
 public NSocketSAEAItem(string uid = "", Socket socket = null)
 {
     this.UID    = uid;
     ReceiveSAEA = new NSocketSocketAsyncEventArgs("receive")
     {
         UID = uid, UserToken = socket
     };
     SendSAEA = new NSocketSocketAsyncEventArgs("send")
     {
         UID = uid, UserToken = socket
     };
     this.LastMessageTime = DateTime.Now;
 }
Exemplo n.º 3
0
        private void ReceiveListen(NSocketSocketAsyncEventArgs e)
        {
            var socket = e.Socket;

            if (socket.Connected)
            {
                Boolean willRaiseEvent = socket.ReceiveAsync(e);
                Console.WriteLine("TID: #{0} prepare to receive next", System.Threading.Thread.CurrentThread.ManagedThreadId);
                if (!willRaiseEvent)
                {
                    ProcessReceive(e);
                }
            }
        }
Exemplo n.º 4
0
 private void ProcessReceive(NSocketSocketAsyncEventArgs e)
 {
     //OnMsgReceived(e.UID, e.SocketError.ToString());
     if (e.BytesTransferred > 0)
     {
         Int32  byteTransferred = e.BytesTransferred;
         string received        = Encoding.Unicode.GetString(e.Buffer, e.Offset, byteTransferred);
         OnMsgReceived(e.UID, received);
         //检查消息的准确性
         //string[] msg = handler.GetActualString(received);
         //foreach (string m in msg)
         //    OnMsgReceived(e.UID, m);
         //可以在这里设一个停顿来实现间隔时间段监听,这里的停顿是单个用户间的监听间隔
         //发送一个异步接受请求,并获取请求是否为成功
     }
     else
     {
         Console.WriteLine(e.BytesTransferred);
     }
 }
Exemplo n.º 5
0
 private void ReceiveListen(NSocketSocketAsyncEventArgs e)
 {
     var socket = e.Socket;
     if (socket.Connected)
     {
         Boolean willRaiseEvent = socket.ReceiveAsync(e);
         Console.WriteLine("TID: #{0} prepare to receive next", System.Threading.Thread.CurrentThread.ManagedThreadId);
         if (!willRaiseEvent)
             ProcessReceive(e);
     }
 }
Exemplo n.º 6
0
 private void ProcessReceive(NSocketSocketAsyncEventArgs e)
 {
     //OnMsgReceived(e.UID, e.SocketError.ToString());
     if (e.BytesTransferred > 0)
     {
         Int32 byteTransferred = e.BytesTransferred;
         string received = Encoding.Unicode.GetString(e.Buffer, e.Offset, byteTransferred);
         OnMsgReceived(e.UID, received);
         //检查消息的准确性
         //string[] msg = handler.GetActualString(received);
         //foreach (string m in msg)
         //    OnMsgReceived(e.UID, m);
         //可以在这里设一个停顿来实现间隔时间段监听,这里的停顿是单个用户间的监听间隔
         //发送一个异步接受请求,并获取请求是否为成功
     }
     else
     {
         Console.WriteLine(e.BytesTransferred);
     }
 }