示例#1
0
        /// <summary>
        /// Receives data asynchronously.
        /// </summary>
        private void ReceivedData(IAsyncResult ar)
        {
            try
            {
                int length = _Socket.EndReceive(ar);
                if (length <= 0)
                {
                    Dispose(); return;
                }

                byte[] packet = new byte[length];
                Array.Copy(_Buffer, packet, length);
                HandleData(packet);
                ServerLogger.Incoming(string.Format("Received data from {0} with data: {1}", ID, Encoding.UTF8.GetString(packet)));
            }
            catch (SocketException) { }
            catch (Exception e) { ServerLogger.Error(e.Message); }
            finally { BeginReceive(); }
        }