상속: System.Net.Sockets.SocketAsyncEventArgs
예제 #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;
 }
예제 #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;
 }
예제 #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);
                }
            }
        }
예제 #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);
     }
 }
예제 #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);
     }
 }
예제 #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);
     }
 }