Пример #1
0
        /// <summary>
        /// new
        /// </summary>
        /// <param name="protocol"></param>
        /// <param name="socketBufferSize"></param>
        /// <param name="messageBufferSize"></param>
        /// <param name="millisecondsSendTimeout"></param>
        /// <param name="millisecondsReceiveTimeout"></param>
        /// <exception cref="ArgumentNullException">protocol is null</exception>
        public SocketClient(Protocol.IProtocol <TMessage> protocol,
                            int socketBufferSize,
                            int messageBufferSize,
                            int millisecondsSendTimeout,
                            int millisecondsReceiveTimeout)
            : base(socketBufferSize, messageBufferSize)
        {
            if (protocol == null)
            {
                throw new ArgumentNullException("protocol");
            }
            this._protocol = protocol;

            if (protocol.IsAsync)
            {
                this._connectionPool = new AsyncPool();
            }
            else
            {
                this._connectionPool = new SyncPool();
            }

            this._millisecondsSendTimeout    = millisecondsSendTimeout;
            this._millisecondsReceiveTimeout = millisecondsReceiveTimeout;

            this._pendingQueue   = new PendingSendQueue(this);
            this._receivingQueue = new ReceivingQueue(this);

            this._endPointManager            = new EndPointManager(this);
            this._endPointManager.Connected += this.OnEndPointConnected;
            this._endPointManager.Already   += this.OnEndPointAlready;
        }
        /// <summary>
        /// new
        /// </summary>
        /// <param name="socketService"></param>
        /// <param name="protocol"></param>
        /// <param name="socketBufferSize"></param>
        /// <param name="messageBufferSize"></param>
        /// <param name="maxMessageSize"></param>
        /// <param name="maxConnections"></param>
        /// <exception cref="ArgumentNullException">socketService is null.</exception>
        /// <exception cref="ArgumentNullException">protocol is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">maxMessageSize</exception>
        /// <exception cref="ArgumentOutOfRangeException">maxConnections</exception>
        public SocketServer(AbsSocketService <TCommandInfo> socketService,
                            Protocol.IProtocol <TCommandInfo> protocol,
                            int socketBufferSize,
                            int messageBufferSize,
                            int maxMessageSize,
                            int maxConnections)
            : base(socketBufferSize, messageBufferSize)
        {
            if (socketService == null)
            {
                throw new ArgumentNullException("socketService");
            }
            if (protocol == null)
            {
                throw new ArgumentNullException("protocol");
            }
            if (maxMessageSize < 1)
            {
                throw new ArgumentOutOfRangeException("maxMessageSize");
            }
            if (maxConnections < 1)
            {
                throw new ArgumentOutOfRangeException("maxConnections");
            }

            this._socketService  = socketService;
            this._protocol       = protocol;
            this._maxMessageSize = maxMessageSize;
            this._maxConnections = maxConnections;
        }
Пример #3
0
        /// <summary>
        /// new
        /// </summary>
        /// <param name="socketService"></param>
        /// <param name="protocol"></param>
        /// <param name="socketBufferSize"></param>
        /// <param name="messageBufferSize"></param>
        /// <param name="maxMessageSize"></param>
        /// <param name="maxConnections"></param>
        /// <exception cref="ArgumentNullException">socketService is null.</exception>
        /// <exception cref="ArgumentNullException">protocol is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">maxMessageSize</exception>
        /// <exception cref="ArgumentOutOfRangeException">maxConnections</exception>
        public SocketServer(IServerHandler handler,
                            Protocol.IProtocol protocol,
                            int socketBufferSize,
                            int messageBufferSize,
                            int maxMessageSize,
                            int maxConnections)
            : base(socketBufferSize, messageBufferSize)
        {
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }
            if (protocol == null)
            {
                throw new ArgumentNullException("protocol");
            }
            if (maxMessageSize < 1)
            {
                throw new ArgumentOutOfRangeException("maxMessageSize");
            }
            if (maxConnections < 1)
            {
                throw new ArgumentOutOfRangeException("maxConnections");
            }

            this._handler        = handler;
            this._protocol       = protocol;
            this._maxMessageSize = maxMessageSize;
            this._maxConnections = maxConnections;
        }
Пример #4
0
        /// <summary>
        /// new
        /// </summary>
        /// <param name="port"></param>
        /// <param name="socketService"></param>
        /// <param name="protocol"></param>
        /// <param name="socketBufferSize"></param>
        /// <param name="messageBufferSize"></param>
        /// <param name="maxMessageSize"></param>
        /// <param name="maxConnections"></param>
        /// <exception cref="ArgumentNullException">socketService is null.</exception>
        /// <exception cref="ArgumentNullException">protocol is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">maxMessageSize</exception>
        /// <exception cref="ArgumentOutOfRangeException">maxConnections</exception>
        public SocketServer(int port,
                            ISocketService <TMessage> socketService,
                            Protocol.IProtocol <TMessage> protocol,
                            int socketBufferSize,
                            int messageBufferSize,
                            int maxMessageSize,
                            int maxConnections)
            : base(socketBufferSize, messageBufferSize)
        {
            if (socketService == null)
            {
                throw new ArgumentNullException("socketService");
            }
            if (protocol == null)
            {
                throw new ArgumentNullException("protocol");
            }
            if (maxMessageSize < 1)
            {
                throw new ArgumentOutOfRangeException("maxMessageSize");
            }
            if (maxConnections < 1)
            {
                throw new ArgumentOutOfRangeException("maxConnections");
            }

            this._socketService  = socketService;
            this._protocol       = protocol;
            this._maxMessageSize = maxMessageSize;
            this._maxConnections = maxConnections;

            this._listener           = new SocketListener(new IPEndPoint(IPAddress.Any, port), this);
            this._listener.Accepted += this.OnAccepted;
        }
Пример #5
0
 public TcpServerChannelHandlerAdapter(
     ISocketService <TMessage> service,
     Protocol.IProtocol <TMessage> protocol
     ) : base(true)
 {
     this._service  = service;
     this._protocol = protocol;
 }
Пример #6
0
 /// <summary>
 /// new
 /// </summary>
 /// <param name="protocol"></param>
 /// <param name="socketBufferSize"></param>
 /// <param name="messageBufferSize"></param>
 /// <param name="millisecondsSendTimeout"></param>
 /// <param name="millisecondsReceiveTimeout"></param>
 /// <exception cref="ArgumentNullException">protocol is null</exception>
 public PooledSocketClient(Protocol.IProtocol <TResponse> protocol,
                           int socketBufferSize,
                           int messageBufferSize,
                           int millisecondsSendTimeout,
                           int millisecondsReceiveTimeout)
     : base(protocol, socketBufferSize, messageBufferSize, millisecondsSendTimeout, millisecondsReceiveTimeout)
 {
     this._serverPool            = this.InitServerPool();
     this._serverPool.Connected += this.OnServerPoolConnected;
 }
Пример #7
0
        public TcpServerBootstrap(
            ISocketService <TMessage> socketService,
            Protocol.IProtocol <TMessage> protocol,
            ILoggerFactory loggerFactory,
            IOptions <TcpHostOption> hostOption = null
            )
        {
            Preconditions.CheckNotNull(protocol, nameof(protocol));
            Preconditions.CheckNotNull(socketService, nameof(socketService));

            this._options       = hostOption?.Value ?? new TcpHostOption();
            this._protocol      = protocol;
            this._socketService = socketService;
            this._logger        = loggerFactory.CreateLogger(GetType());
        }
Пример #8
0
        /// <summary>
        /// new
        /// </summary>
        /// <param name="protocol"></param>
        /// <param name="socketBufferSize"></param>
        /// <param name="messageBufferSize"></param>
        /// <param name="millisecondsSendTimeout"></param>
        /// <param name="millisecondsReceiveTimeout"></param>
        /// <exception cref="ArgumentNullException">protocol is null</exception>
        public BaseSocketClient(Protocol.IProtocol <TResponse> protocol,
                                int socketBufferSize,
                                int messageBufferSize,
                                int millisecondsSendTimeout,
                                int millisecondsReceiveTimeout)
            : base(socketBufferSize, messageBufferSize)
        {
            if (protocol == null)
            {
                throw new ArgumentNullException("protocol");
            }
            this._protocol = protocol;

            this._millisecondsSendTimeout    = millisecondsSendTimeout;
            this._millisecondsReceiveTimeout = millisecondsReceiveTimeout;

            this._pendingQueue      = new PendingSendQueue(this, millisecondsSendTimeout);
            this._requestCollection = new RequestCollection(this, millisecondsReceiveTimeout);
        }
Пример #9
0
 /// <summary>
 /// new
 /// </summary>
 /// <param name="protocol"></param>
 public PooledSocketClient(Protocol.IProtocol <TResponse> protocol)
     : this(protocol, 8192, 9192, 3000, 3000)
 {
 }
Пример #10
0
 public SocketContext(IChannel channel, Protocol.IProtocol <TMessage> protocol)
 {
     this._channel  = channel;
     this._protocol = protocol;
 }
Пример #11
0
 /// <summary>
 /// new
 /// </summary>
 /// <param name="protocol"></param>
 public BaseSocketClient(Protocol.IProtocol <TResponse> protocol)
     : this(protocol, 8192, 8192, 3000, 3000)
 {
 }
Пример #12
0
 public TcpClientChannelHandlerAdapter(ISocketClient <TMessage> client, Protocol.IProtocol <TMessage> protocol)
 {
     this._client   = client;
     this._protocol = protocol;
 }
Пример #13
0
 //uart
 public IPCamera(T t, string port_name, int baud_rate, int data_bit)
 {
     camera = new Protocol.Rs232 <T>(t, port_name, baud_rate, data_bit);
 }
Пример #14
0
 //telnet
 public IPCamera(T t, string ip, string _telnet_user, string _telnet_pass)
 {
     camera      = new Protocol.Telnet <T>(t, ip, 23);
     telnet_user = _telnet_user;
     telnet_pass = _telnet_pass;
 }
Пример #15
0
 /// <summary>
 /// new
 /// </summary>
 /// <param name="protocol"></param>
 public SocketClient(Protocol.IProtocol <TMessage> protocol)
     : this(protocol, 8192, 8192, 3000, 3000)
 {
 }
Пример #16
0
 public ChannelDecodeHandler(Protocol.IProtocol <TMessage> protocol)
 {
     this._protocol = protocol;
 }