Esempio n. 1
0
 public SocketService(ISocketEventListener socketEventListener)
 {
     _socketEventListener = socketEventListener;
     _logger = ObjectContainer.Resolve <ILoggerFactory>()
               .Create(GetType()
                       .FullName);
 }
Esempio 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();
 }
 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;
 }
Esempio 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();
 }
Esempio 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);
 }
Esempio 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();
            }
        }
Esempio 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);
 }
Esempio 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);
 }
Esempio 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;
 }
Esempio 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;
            }
        }
Esempio 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);
 }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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));
 }
Esempio 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;
 }
Esempio n. 16
0
 /// <summary>
 /// Create an instance
 /// </summary>
 /// <param name="listener"></param>
 public XEP124Socket(ISocketEventListener listener) : base(listener)
 {
 }
Esempio n. 17
0
 public ClientSocket(ISocketEventListener socketEventListener)
 {
     _socketService = new SocketService(socketEventListener);
     _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName);
 }
Esempio n. 18
0
 /// <summary>
 /// Construct a BaseSocket.
 /// </summary>
 /// <param name="listener"></param>
 protected BaseSocket(ISocketEventListener listener)
 {
     Debug.Assert(listener != null);
     m_listener = listener;
 }
Esempio 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;
        }
Esempio n. 20
0
 /// <summary>
 /// Create an instance
 /// </summary>
 /// <param name="listener"></param>
 public XEP25Socket(ISocketEventListener listener)
 {
     Debug.Assert(listener != null);
     m_listener = listener;
 }
Esempio 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;
        }
Esempio 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);
 }
Esempio 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);
 }
Esempio 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);
 }
Esempio 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);
 }
Esempio 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));
 }
Esempio 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));
 }
Esempio 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)
 {
 }
Esempio 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;
 }
Esempio 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;
 }
Esempio 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;
 }
Esempio n. 32
0
 public void SetSocketEventListener(ISocketEventListener listener)
 {
     eventListener = listener;
 }
Esempio n. 33
0
 /// <summary>
 /// Create an instance
 /// </summary>
 /// <param name="listener"></param>
 public XEP124Socket(ISocketEventListener listener)
     : base(listener)
 {
     RemoteCertificate = null;
     StartStream = false;
 }
Esempio n. 34
0
 /// <summary>
 /// Construct a BaseSocket.
 /// </summary>
 /// <param name="listener"></param>
 protected BaseSocket(ISocketEventListener listener)
 {
     Debug.Assert(listener != null);
     m_listener = listener;
 }
Esempio 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)
 {
 }
Esempio 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));
 }
Esempio 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)
 {
 }
Esempio 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)
 {
 }
Esempio n. 39
0
 /// <summary>
 /// Create an instance
 /// </summary>
 /// <param name="listener"></param>
 public XEP25Socket(ISocketEventListener listener)
 {
     Debug.Assert(listener != null);
     m_listener = listener;
 }
Esempio 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)
 {
 }
Esempio 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)
 {
 }
Esempio n. 42
0
 /// <summary>
 /// Create an instance
 /// </summary>
 /// <param name="listener"></param>
 public XEP124Socket(ISocketEventListener listener) 
     : base(listener)
 { }