Example #1
0
        protected override void OnSocketDataReceived(TCPSocket socket, SocketDataReceivedEventArgs args)
        {
            Message message;
            int pos  = 0;
            byte[] buffer = args.Packet.Buffer;
            byte[] data = new byte[buffer.Length];

            while (pos < args.Packet.Length) {
                buffer.CopyTo(data, pos);
                if (!Message.TryParse(data, out message)) return;
                OnMessageReceived(message);
                pos += message.Length + 1;
            }
            base.OnSocketDataReceived(socket, args);
        }
 ///////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Accepts a new client connection
 /// </summary>
 /// <param name="result">The object containing information about the new connection</param>
 ///////////////////////////////////////////////////////////////////////////////////////////
 protected override void OnSocketException(TCPSocket socket, SocketExceptionEventArgs args)
 {
     if (args.Exception.ErrorCode == (int)SocketError.ConnectionReset) {
         if (args.RemoteEndPoint != null)
             this[args.RemoteEndPoint].Disconnect(); //Connection thread will remove it
     }
     base.OnSocketException(socket, args);
 }
 protected override void OnSocketException(TCPSocket socket, SocketExceptionEventArgs args)
 {
     if ((args.Exception.ErrorCode == 10054) || (args.Exception.ErrorCode == 10053))
     {
         base.Disconnect();
     }
 }
 ///////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Handles the ConnectionReset socket error
 /// </summary>
 ///////////////////////////////////////////////////////////////////////////////////////////
 protected override void OnSocketException(TCPSocket socket, SocketExceptionEventArgs args)
 {
     if (args.Exception.ErrorCode == (int)SocketError.ConnectionReset) {
         Disconnect();
     }
     base.OnSocketException(socket, args);
 }
 protected virtual void OnSocketException(TCPSocket socket, SocketExceptionEventArgs args)
 {
     if(SocketException != null) SocketException(socket, args);
 }
 protected virtual void OnSocketDataReceived(TCPSocket socket, SocketDataReceivedEventArgs args)
 {
     if (DataReceived != null) DataReceived(socket, args);
 }