示例#1
0
        public ServerSocket(EndPoint localEP, SocketSetting socketSetting)
        {
            LocalEndPoint = localEP;
            Backlog       = socketSetting.Backlog;

            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            _socketSetting = socketSetting;

            _acceptSocketAsyncEventArgs            = new SocketAsyncEventArgs();
            _acceptSocketAsyncEventArgs.Completed += AcceptSocketAsyncEventArgs_Completed;

            _clientSocketDict = new ConcurrentDictionary <Guid, TcpConnection>();
        }
示例#2
0
        public ClientSocket(EndPoint localEP, EndPoint remoteEP, SocketSetting socketSetting)
        {
            LocalEP  = localEP;
            RemoteEP = remoteEP;

            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            _socketSetting = socketSetting;

            _connectSocketAsyncEventArgs            = new SocketAsyncEventArgs();
            _connectSocketAsyncEventArgs.Completed += ConnectSocketAsyncEventArgs_Completed;

            _manualResetEvent = new ManualResetEvent(false);
        }
示例#3
0
        public TcpConnection(Socket socket, SocketSetting socketSeting)
        {
            _socket = socket;

            _sendSocketAsyncEvent = new SocketAsyncEventArgs();
            _sendSocketAsyncEvent.AcceptSocket = socket;
            _sendSocketAsyncEvent.Completed   += SendSocketAsyncEvent_Completed;

            _receiveSocketAsyncEvent = new SocketAsyncEventArgs();
            _receiveSocketAsyncEvent.AcceptSocket = socket;
            _receiveSocketAsyncEvent.Completed   += ReceiveSocketAsyncEvent_Completed;

            _sendQueue  = new ConcurrentQueue <byte[]>();
            _bufferPool = new BufferPool(socketSeting.ReceiveBufferSize, socketSeting.ReceiveDataBufferPoolSize, socketSeting.ReceiveDataBufferPoolMaxSize, socketSeting.ReceiveDataBufferPoolMinSize);
            TryReceive();
            TrySend();
        }