Exemple #1
0
        public void Setup(TcpClient client, ISocketMessageProcessor processor)
        {
            lock (this)
            {
                if (client == null)
                {
                    throw new ArgumentNullException("client");
                }
                if (processor == null)
                {
                    throw new ArgumentNullException("processor");
                }
                if (this.Status != SocketStatus.Disconnected)
                {
                    throw new InvalidOperationException("You can't setup a socket if it isn't disconnected.");
                }
                Log.DebugFormat("Setup {0}", client.Client.RemoteEndPoint);
                this.EndPoint         = client.Client.RemoteEndPoint as IPEndPoint;
                this.MessageProcessor = processor;
                this.Client           = client;
                this.Status           = SocketStatus.Connected;
            }
            this.CallOnConnectionEvent(this.FirstConnection ? SocketConnectionEvent.Connected : SocketConnectionEvent.Reconnected);
            this.FirstConnection = false;
            var bundle = new SocketReceiveBundle(this.Client);

            this.Client.Client.BeginReceive(
                bundle.Buffer,
                0,
                SocketReceiveBundle.BufferSize,
                SocketFlags.None,
                this.EndReceive,
                bundle);
        }
Exemple #2
0
 public void Setup(IPEndPoint ep, ISocketMessageProcessor processor)
 {
     lock (this)
     {
         if (ep == null)
         {
             throw new ArgumentNullException("ep");
         }
         if (processor == null)
         {
             throw new ArgumentNullException("processor");
         }
         if (this.Status != SocketStatus.Disconnected)
         {
             throw new InvalidOperationException("You can't setup a socket if it isn't disconnected.");
         }
         Log.DebugFormat("Setup {0}", ep);
         this.EndPoint = ep;
         if (this.Client != null)
         {
             try { this.Client.Close(); }
             catch { }
         }
         this.Client           = new TcpClient();
         this.MessageProcessor = processor;
     }
 }
Exemple #3
0
 public void Setup(IPEndPoint ep, ISocketMessageProcessor processor)
 {
     lock (this)
     {
         if (ep == null) throw new ArgumentNullException("ep");
         if (processor == null) throw new ArgumentNullException("processor");
         if (this.Status != SocketStatus.Disconnected) throw new InvalidOperationException("You can't setup a socket if it isn't disconnected.");
         Log.DebugFormat("Setup {0}", ep);
         this.EndPoint = ep;
         if (this.Client != null)
         {
             try { this.Client.Close(); }
             catch { }
         }
         this.Client = new TcpClient();
         this.MessageProcessor = processor;
     }
 }
Exemple #4
0
        public void Setup(TcpClient client, ISocketMessageProcessor processor)
        {
            lock (this)
            {
                if(client == null)throw new ArgumentNullException("client");
                if (processor == null) throw new ArgumentNullException("processor");
                if (this.Status != SocketStatus.Disconnected) throw new InvalidOperationException("You can't setup a socket if it isn't disconnected.");
				Log.DebugFormat("Setup {0}",client.Client.RemoteEndPoint);
                this.EndPoint = client.Client.RemoteEndPoint as IPEndPoint;
                this.MessageProcessor = processor;
                this.Client = client;
                this.Status = SocketStatus.Connected;
            }
            this.CallOnConnectionEvent(this.FirstConnection ? SocketConnectionEvent.Connected : SocketConnectionEvent.Reconnected);
            this.FirstConnection = false;
            var bundle = new SocketReceiveBundle(this.Client);
            this.Client.Client.BeginReceive(
                bundle.Buffer,
                0,
                SocketReceiveBundle.BufferSize,
                SocketFlags.None,
                this.EndReceive,
                bundle);
        }