示例#1
0
 private void WaitForData()
 {
     try
     {
         SocketPackets SockPack = new SocketPackets();
         SockPack.CurrentSocket = m_socListener;
         m_socListener.BeginReceive(SockPack.DataBuffer, 0, SockPack.DataBuffer.Length, SocketFlags.None, new AsyncCallback(OnDataReceived), SockPack);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
示例#2
0
        private void OnDataReceived(IAsyncResult ar)
        {
            SocketPackets theSockID = (SocketPackets)ar.AsyncState;

            int Irx = 0;

            Irx = theSockID.CurrentSocket.EndReceive(ar);
            char[]  chars   = new char[Irx + 1];
            Decoder decoder = Encoding.UTF8.GetDecoder();
            int     charlen = decoder.GetChars(theSockID.DataBuffer, 0, Irx, chars, 0);
            string  sZData  = new string(chars);

            Console.Write(sZData);
            WaitForData();
            SendData();
        }