Exemplo n.º 1
0
 public SocketService(ISocketEventListener socketEventListener)
 {
     _socketEventListener = socketEventListener;
     _logger = ObjectContainer.Resolve <ILoggerFactory>()
               .Create(GetType()
                       .FullName);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Create a socket.  This starts a thread for background processing, but the thread is mostly paused
 /// waiting for new requests.
 /// </summary>
 public HttpSocket(ISocketEventListener listener) : base(listener)
 {
     m_thread              = new Thread(new ThreadStart(ProcessThread));
     m_thread.Name         = "HTTP processing thread";
     m_thread.IsBackground = true;
     m_thread.Start();
 }
Exemplo n.º 3
0
 public SocketRemotingServer(string name, SocketSetting socketSetting, ISocketEventListener socketEventListener = null)
 {
     _serverSocket = new ServerSocket(socketEventListener);
     _requestHandlerDict = new Dictionary<int, IRequestHandler>();
     _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(name ?? GetType().Name);
     _serverSocket.Bind(socketSetting.Address, socketSetting.Port).Listen(socketSetting.Backlog);
     _started = false;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Create a socket.  This starts a thread for background processing, but the thread is mostly paused
 /// waiting for new requests.
 /// </summary>
 public HttpSocket(ISocketEventListener listener)
     : base(listener)
 {
     m_thread = new Thread(new ThreadStart(ProcessThread));
     m_thread.Name = "HTTP processing thread";
     m_thread.IsBackground = true;
     m_thread.Start();
 }
Exemplo n.º 5
0
 public ServerSocket(ISocketEventListener socketEventListener)
 {
     _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     _socketEventListener = socketEventListener;
     _socketService = new SocketService(socketEventListener);
     _newClientSocketSignal = new ManualResetEvent(false);
     _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName);
 }
Exemplo n.º 6
0
        private void AcceptDone(AsyncSocket cliCon)
        {
            cliCon.m_addr     = m_addr;
            cliCon.Address.IP = ((IPEndPoint)cliCon.m_sock.RemoteEndPoint).Address;
            cliCon.State      = SocketState.Connected;

            cliCon.m_stream          = new NetworkStream(cliCon.m_sock);
            cliCon.m_server          = true;
            cliCon.LocalCertificate  = m_cert;
            cliCon.RequireClientCert = m_requireClientCert;

            ISocketEventListener l = m_listener.GetListener(cliCon);

            if (l == null)
            {
                // if the listener returns null, close the socket and
                // quit, instead of asserting.
                cliCon.m_sock.Close();
                RequestAccept();
                return;
            }

            cliCon.m_listener = l;

            try
            {
                if (m_watcher != null)
                {
                    m_watcher.RegisterSocket(cliCon);
                }
            }
            catch (InvalidOperationException)
            {
                // m_watcher out of slots.
                cliCon.AsyncClose();

                // don't set state
                // they really don't need this error, we don't think.
                // Error(e);

                // tell the watcher that when it gets its act together,
                // we'd appreciate it if it would restart the RequestAccept().
                m_watcher.PendingAccept(this);
                return;
            }

            if (m_secureProtocol != SslProtocols.None)
            {
                cliCon.StartTLS();
            }

            if (l.OnAccept(cliCon))
            {
                RequestAccept();
            }
        }
Exemplo n.º 7
0
 public SocketRemotingServer(string name, SocketSetting socketSetting, ISocketEventListener socketEventListener = null)
 {
     _serverSocket       = new ServerSocket(socketEventListener);
     _requestHandlerDict = new Dictionary <int, IRequestHandler>();
     _logger             = ObjectContainer.Resolve <ILoggerFactory>()
                           .Create(name ?? GetType()
                                   .Name);
     _serverSocket.Bind(socketSetting.Address, socketSetting.Port)
     .Listen(socketSetting.Backlog);
 }
Exemplo n.º 8
0
 public ServerSocket(ISocketEventListener socketEventListener)
 {
     _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     _socketEventListener   = socketEventListener;
     _socketService         = new SocketService(socketEventListener);
     _newClientSocketSignal = new ManualResetEvent(false);
     _logger = ObjectContainer.Resolve <ILoggerFactory>()
               .Create(GetType()
                       .FullName);
 }
Exemplo n.º 9
0
 public ServerSocket(ISocketEventListener socketEventListener)
 {
     _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     _clientSocketDict = new ConcurrentDictionary<string, SocketInfo>();
     _socketEventListener = socketEventListener;
     _socketService = new SocketService(NotifySocketReceiveException);
     _newClientSocketSignal = new ManualResetEvent(false);
     _scheduleService = ObjectContainer.Resolve<IScheduleService>();
     _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().Name);
     _running = false;
 }
Exemplo n.º 10
0
        /// <summary>
        /// Called from SocketWatcher.
        /// </summary>
        /// <param name="w"></param>
        /// <param name="listener">The listener for this socket</param>
        /// <param name="SSL">Do SSL3 and TLS1 on startup (call
        /// StartTLS later if this is false, and TLS only is needed
        /// later)</param>
        /// <param name="synch">Synchronous operation</param>
        public AsyncSocket(SocketWatcher w,
                           ISocketEventListener listener,
                           bool SSL,
                           bool synch) :
            base(listener)
        {
            m_watcher = w;
            m_synch   = synch;

            if (SSL)
            {
                m_secureProtocol = SSLProtocols;
            }
        }
Exemplo n.º 11
0
 public SocketRemotingClient(string address, int port, ISocketEventListener socketEventListener = null)
 {
     _lockObject1         = new object();
     _lockObject2         = new object();
     _address             = address;
     _port                = port;
     _socketEventListener = socketEventListener;
     _clientSocket        = new ClientSocket(new RemotingClientSocketEventListener(this));
     _responseFutureDict  = new ConcurrentDictionary <long, ResponseFuture>();
     _messageQueue        = new BlockingCollection <byte[]>(new ConcurrentQueue <byte[]>());
     _scheduleService     = ObjectContainer.Resolve <IScheduleService>();
     _worker              = new Worker("SocketRemotingClient.HandleMessage", HandleMessage);
     _logger              = ObjectContainer.Resolve <ILoggerFactory>()
                            .Create(GetType()
                                    .FullName);
 }
Exemplo n.º 12
0
        /// <summary>
        /// Create a socket that is listening for inbound connections.
        /// </summary>
        /// <param name="listener">Where to send notifications</param>
        /// <param name="addr">Address to connect to</param>
        /// <param name="backlog">The maximum length of the queue of pending connections</param>
        /// <param name="SSL">Do SSL3/TLS1 on connect</param>
        /// <returns>A socket that is ready for calling RequestAccept()</returns>
        public AsyncSocket CreateListenSocket(ISocketEventListener listener,
                                              Address addr,
                                              int backlog,
                                              bool SSL)
        {
            //Debug.Assert(m_maxSocks > 1);
            AsyncSocket result = new AsyncSocket(this, listener, SSL, m_synch);

            if (SSL)
            {
                result.LocalCertificate  = m_cert;
                result.RequireClientCert = m_requireClientCert;
            }
            result.Accept(addr, backlog);
            return(result);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Create an outbound socket.
        /// </summary>
        /// <param name="listener">Where to send notifications</param>
        /// <param name="addr">Address to connect to</param>
        /// <param name="SSL">Do SSL3/TLS1 on startup</param>
        /// <param name="hostId">The logical name of the host to connect to, for SSL/TLS purposes.</param>
        /// <returns>Socket that is in the process of connecting</returns>
        public AsyncSocket CreateConnectSocket(ISocketEventListener listener,
                                               Address addr,
                                               bool SSL,
                                               string hostId)
        {
            AsyncSocket result;

            // Create the socket:
            result = new AsyncSocket(this, listener, SSL, m_synch);
            if (SSL)
            {
                result.LocalCertificate = m_cert;
            }

            // Start the connect process:
            result.Connect(addr, hostId);
            return(result);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Create a socket that is listening for inbound connections, with no SSL/TLS.
 /// </summary>
 /// <param name="listener">Where to send notifications</param>
 /// <param name="addr">Address to connect to</param>
 /// <returns>A socket that is ready for calling RequestAccept()</returns>
 public AsyncSocket CreateListenSocket(ISocketEventListener listener,
                                       Address addr)
 {
     return(CreateListenSocket(listener, addr, 5, false));
 }
Exemplo n.º 15
0
 /// <summary>
 /// Create a socket that is listening for inbound connections.
 /// </summary>
 /// <param name="listener">Where to send notifications</param>
 /// <param name="addr">Address to connect to</param>
 /// <param name="backlog">The maximum length of the queue of pending connections</param>
 /// <param name="SSL">Do SSL3/TLS1 on connect</param>
 /// <returns>A socket that is ready for calling RequestAccept()</returns>
 public AsyncSocket CreateListenSocket(ISocketEventListener listener,
                                       Address              addr,
                                       int                  backlog,
                                       bool                 SSL)
 {
     //Debug.Assert(m_maxSocks > 1);
     AsyncSocket result = new AsyncSocket(this, listener, SSL, m_synch);
     if (SSL)
     {
         result.LocalCertificate = m_cert;
         result.RequireClientCert = m_requireClientCert;
     }
     result.Accept(addr, backlog);
     return result;
 }
Exemplo n.º 16
0
 /// <summary>
 /// Create an instance
 /// </summary>
 /// <param name="listener"></param>
 public XEP124Socket(ISocketEventListener listener) : base(listener)
 {
 }
Exemplo n.º 17
0
 public ClientSocket(ISocketEventListener socketEventListener)
 {
     _socketService = new SocketService(socketEventListener);
     _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Construct a BaseSocket.
 /// </summary>
 /// <param name="listener"></param>
 protected BaseSocket(ISocketEventListener listener)
 {
     Debug.Assert(listener != null);
     m_listener = listener;
 }
Exemplo n.º 19
0
        /// <summary>
        /// Called from SocketWatcher.
        /// </summary>
        /// <param name="w"></param>
        /// <param name="listener">The listener for this socket</param>
        /// <param name="SSL">Do SSL3 and TLS1 on startup (call
        /// StartTLS later if this is false, and TLS only is needed
        /// later)</param>
        /// <param name="synch">Synchronous operation</param>
        public AsyncSocket(SocketWatcher w,
                           ISocketEventListener listener,
                           bool SSL,
                           bool synch) :
            base(listener)
        {
            m_watcher = w;
            m_synch = synch;

            if (SSL)
                m_secureProtocol = SSLProtocols;
        }
Exemplo n.º 20
0
 /// <summary>
 /// Create an instance
 /// </summary>
 /// <param name="listener"></param>
 public XEP25Socket(ISocketEventListener listener)
 {
     Debug.Assert(listener != null);
     m_listener = listener;
 }
Exemplo n.º 21
0
        /// <summary>
        /// Create an outbound socket.
        /// </summary>
        /// <param name="listener">Where to send notifications</param>
        /// <param name="addr">Address to connect to</param>
        /// <param name="SSL">Do SSL3/TLS1 on startup</param>
        /// <param name="hostId">The logical name of the host to connect to, for SSL/TLS purposes.</param>
        /// <returns>Socket that is in the process of connecting</returns>
        public AsyncSocket CreateConnectSocket(ISocketEventListener listener,
                                               Address              addr,
                                               bool                 SSL,
                                               string               hostId)
        {
            AsyncSocket result;

            // Create the socket:
            result = new AsyncSocket(this, listener, SSL, m_synch);
            if (SSL)
                result.LocalCertificate = m_cert;

            // Start the connect process:
            result.Connect(addr, hostId);
            return result;
        }
Exemplo n.º 22
0
 /// <summary>
 /// Create an outbound socket.
 /// </summary>
 /// <param name="listener">Where to send notifications</param>
 /// <param name="addr">Address to connect to</param>
 /// <returns>Socket that is in the process of connecting</returns>
 public AsyncSocket CreateConnectSocket(ISocketEventListener listener,
                                        Address              addr)
 {
     return CreateConnectSocket(listener, addr, false, null);
 }
Exemplo n.º 23
0
 /// <summary>
 /// Create a socket that is listening for inbound connections, with no SSL/TLS.
 /// </summary>
 /// <param name="listener">Where to send notifications</param>
 /// <param name="addr">Address to connect to</param>
 /// <param name="backlog">The maximum length of the queue of pending connections</param>
 /// <returns>A socket that is ready for calling RequestAccept()</returns>
 public AsyncSocket CreateListenSocket(ISocketEventListener listener,
                                       Address              addr,
                                       int                  backlog)
 {
     return CreateListenSocket(listener, addr, backlog, false);
 }
Exemplo n.º 24
0
 /// <summary>
 /// Create a socket that is listening for inbound connections, with no SSL/TLS.
 /// </summary>
 /// <param name="listener">Where to send notifications</param>
 /// <param name="addr">Address to connect to</param>
 /// <returns>A socket that is ready for calling RequestAccept()</returns>
 public AsyncSocket CreateListenSocket(ISocketEventListener listener,
     Address              addr)
 {
     return CreateListenSocket(listener, addr, 5, false);
 }
Exemplo n.º 25
0
 /// <summary>
 /// Create a socket that is listening for inbound connections.
 /// </summary>
 /// <param name="listener">Where to send notifications</param>
 /// <param name="addr">Address to connect to</param>
 /// <param name="SSL">Do SSL3/TLS1 on connect</param>
 /// <returns>A socket that is ready for calling RequestAccept()</returns>
 public AsyncSocket CreateListenSocket(ISocketEventListener listener,
                                       Address              addr,
                                       bool                 SSL)
 {
     return CreateListenSocket(listener, addr, 5, SSL);
 }
Exemplo n.º 26
0
 /// <summary>
 /// Create a socket that is listening for inbound connections, with no SSL/TLS.
 /// </summary>
 /// <param name="listener">Where to send notifications</param>
 /// <param name="addr">Address to connect to</param>
 /// <param name="backlog">The maximum length of the queue of pending connections</param>
 /// <returns>A socket that is ready for calling RequestAccept()</returns>
 public AsyncSocket CreateListenSocket(ISocketEventListener listener,
                                       Address addr,
                                       int backlog)
 {
     return(CreateListenSocket(listener, addr, backlog, false));
 }
Exemplo n.º 27
0
 /// <summary>
 /// Create an outbound socket.
 /// </summary>
 /// <param name="listener">Where to send notifications</param>
 /// <param name="addr">Address to connect to</param>
 /// <returns>Socket that is in the process of connecting</returns>
 public AsyncSocket CreateConnectSocket(ISocketEventListener listener,
                                        Address addr)
 {
     return(CreateConnectSocket(listener, addr, false, null));
 }
Exemplo n.º 28
0
 /// <summary>
 /// Wrap an existing socket event listener with a Socks5 proxy.  Make SURE to set Socket after this.
 /// </summary>
 /// <param name="chain">Event listener to pass events through to.</param>
 public Socks5Proxy(ISocketEventListener chain) : base(chain)
 {
 }
Exemplo n.º 29
0
 /// <summary>
 /// Called from SocketWatcher.
 /// </summary>
 /// <param name="w"></param>
 /// <param name="listener">The listener for this socket</param>
 public AsyncSocket(SocketWatcher w, ISocketEventListener listener)
     : base(listener)
 {
     m_watcher = w;
 }
Exemplo n.º 30
0
 /// <summary>
 /// Wrap an existing socket event listener with a proxy.  Make SURE to set Socket after this.
 /// </summary>
 /// <param name="chain">Event listener to pass events through to.</param>
 public ProxySocket(ISocketEventListener chain)
     : base(chain)
 {
     Password = null;
     Username = null;
 }
Exemplo n.º 31
0
 /// <summary>
 /// Called from SocketWatcher.
 /// </summary>
 /// <param name="w"></param>
 /// <param name="listener">The listener for this socket</param>
 public AsyncSocket(SocketWatcher w, ISocketEventListener listener) : base(listener)
 {
     m_watcher = w;
 }
Exemplo n.º 32
0
 public void SetSocketEventListener(ISocketEventListener listener)
 {
     eventListener = listener;
 }
Exemplo n.º 33
0
 /// <summary>
 /// Create an instance
 /// </summary>
 /// <param name="listener"></param>
 public XEP124Socket(ISocketEventListener listener)
     : base(listener)
 {
     RemoteCertificate = null;
     StartStream = false;
 }
Exemplo n.º 34
0
 /// <summary>
 /// Construct a BaseSocket.
 /// </summary>
 /// <param name="listener"></param>
 protected BaseSocket(ISocketEventListener listener)
 {
     Debug.Assert(listener != null);
     m_listener = listener;
 }
Exemplo n.º 35
0
 /// <summary>
 /// Wrap an existing socket event listener with a ShttpProxy proxy.  Make SURE to set Socket after this.
 /// </summary>
 /// <param name="chain">Event listener to pass events through to.</param>
 public ShttpProxy(ISocketEventListener chain) : base(chain)
 {
 }
Exemplo n.º 36
0
 /// <summary>
 /// Create a socket that is listening for inbound connections.
 /// </summary>
 /// <param name="listener">Where to send notifications</param>
 /// <param name="addr">Address to connect to</param>
 /// <param name="SSL">Do SSL3/TLS1 on connect</param>
 /// <returns>A socket that is ready for calling RequestAccept()</returns>
 public AsyncSocket CreateListenSocket(ISocketEventListener listener,
                                       Address addr,
                                       bool SSL)
 {
     return(CreateListenSocket(listener, addr, 5, SSL));
 }
Exemplo n.º 37
0
 /// <summary>
 /// Wrap an existing socket event listener with a proxy.  Make SURE to set Socket after this.
 /// </summary>
 /// <param name="chain">Event listener to pass events through to.</param>
 public ProxySocket(ISocketEventListener chain) : base(chain)
 {
 }
Exemplo n.º 38
0
 /// <summary>
 /// Create a socket.  This starts a thread for background processing, but the thread is mostly paused
 /// waiting for new requests.
 /// </summary>
 public HttpSocket(ISocketEventListener listener) : base(listener)
 {
 }
Exemplo n.º 39
0
 /// <summary>
 /// Create an instance
 /// </summary>
 /// <param name="listener"></param>
 public XEP25Socket(ISocketEventListener listener)
 {
     Debug.Assert(listener != null);
     m_listener = listener;
 }
Exemplo n.º 40
0
 /// <summary>
 /// Create a socket.  This starts a thread for background processing, but the thread is mostly paused
 /// waiting for new requests.
 /// </summary>
 public HttpSocket(ISocketEventListener listener)
     : base(listener)
 {
 }
Exemplo n.º 41
0
 /// <summary>
 /// Wrap an existing socket event listener with a proxy.  Make SURE to set Socket after this.
 /// </summary>
 /// <param name="chain">Event listener to pass events through to.</param>
 public ProxySocket(ISocketEventListener chain) : base(chain)
 {
 }
Exemplo n.º 42
0
 /// <summary>
 /// Create an instance
 /// </summary>
 /// <param name="listener"></param>
 public XEP124Socket(ISocketEventListener listener) 
     : base(listener)
 { }