Exemple #1
0
        /// <summary>
        /// JYTCPClient类构造函数
        /// </summary>
        /// <param name="ipAddress">连接的远端ip位置</param>
        /// <param name="port">连接的远端端口号</param>
        /// <param name="dataType">TCP缓存存放的资料类型</param>
        /// <param name="bufferSize">TCP缓存的大小</param>
        public JYTCPClient(string ipAddress, int port, ChannelDataType dataType = ChannelDataType.DataStream, int bufferSize = 131072)
        {
            _ipAddress = ipAddress;
            _port      = port;
            _dataType  = dataType;

            _client = new JYAsyncTcpClient(_ipAddress, _port);
            if (_client == null)
            {
                throw new Exception("客户端建立失败!");
            }
            _bufferSize = bufferSize;//默认100KB

            switch (_dataType)
            {
            case ChannelDataType.DataStream:
                _buffer = new CircularBuffer <byte>((int)_bufferSize);
                _client.DatagramReceived += _client_DatagramReceived;
                break;

            case ChannelDataType.String:
                _buffer = new StringBuffer((int)_bufferSize);
                _client.PlaintextReceived += _client_PlaintextReceived;
                break;

            default:
                break;
            }
            _client.ServerDisconnected += _client_ServerDisconnected;
            _client.Retries             = 10;
            _client.RetryInterval       = 1;
        }
Exemple #2
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="ipAddress">IP地址</param>
        /// <param name="port">端口</param>
        public JYTCPClient(String ipAddress, int port)
        {
            _ipAddress = ipAddress;
            _port      = port;
            _client    = new JYAsyncTcpClient(_ipAddress, _port);
            if (_client == null)
            {
                throw new Exception("客户端建立失败!");
            }
            _bufferSize = 1024 * 1024 * 100;//10MB

            _cricularBuffer = new CircularBuffer <byte>((int)_bufferSize);

            _client.ServerDisconnected += _client_ServerDisconnected;
            _client.DatagramReceived   += _client_DatagramReceived;
            _client.Retries             = 10;
            _client.RetryInterval       = 1;
        }