Пример #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);
        }
Пример #2
0
 ///////////////////////////////////////////////////////////////////////////////////////////
 /// <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);
 }
Пример #3
0
 protected override void OnSocketException(TCPSocket socket, SocketExceptionEventArgs args)
 {
     if ((args.Exception.ErrorCode == 10054) || (args.Exception.ErrorCode == 10053))
     {
         base.Disconnect();
     }
 }
Пример #4
0
 ///////////////////////////////////////////////////////////////////////////////////////////
 /// <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);
 }
Пример #5
0
 protected virtual void OnSocketException(TCPSocket socket, SocketExceptionEventArgs args)
 {
     if(SocketException != null) SocketException(socket, args);
 }
Пример #6
0
 protected virtual void OnSocketDataReceived(TCPSocket socket, SocketDataReceivedEventArgs args)
 {
     if (DataReceived != null) DataReceived(socket, args);
 }