コード例 #1
0
            /// <summary>
            /// new
            /// </summary>
            /// <param name="connectionID"></param>
            /// <param name="socket"></param>
            /// <param name="host"></param>
            /// <exception cref="ArgumentNullException">socket is null</exception>
            /// <exception cref="ArgumentNullException">host is null</exception>
            public DefaultConnection(long connectionID, Socket socket, BaseHost <TSendMessageInfo, TMessage> host)
            {
                if (host == null)
                {
                    throw new ArgumentNullException("host");
                }

                this.ConnectionID       = connectionID;
                this._socket            = socket ?? throw new ArgumentNullException("socket");
                this._messageBufferSize = host.MessageBufferSize;
                this._host = host;

                try {
                    this.LocalEndPoint  = (IPEndPoint)socket.LocalEndPoint;
                    this.RemoteEndPoint = (IPEndPoint)socket.RemoteEndPoint;
                } catch (Exception ex) { Log.Trace.Error("get socket endPoint error.", ex); }

                //init send
                this._saeSend            = host._saePool.Acquire();
                this._saeSend.Completed += this.SendAsyncCompleted;
                this._messageQueue       = new MessageQueue(this.SendMessageInternal);

                //init receive
                this._saeReceive            = host._saePool.Acquire();
                this._saeReceive.Completed += this.ReceiveAsyncCompleted;
            }
コード例 #2
0
            /// <summary>
            /// new
            /// </summary>
            /// <param name="connectionID"></param>
            /// <param name="socket"></param>
            /// <param name="host"></param>
            /// <exception cref="ArgumentNullException">socket is null</exception>
            /// <exception cref="ArgumentNullException">host is null</exception>
            public DefaultConnection(long connectionID, Socket socket, BaseHost host)
            {
                if (socket == null)
                {
                    throw new ArgumentNullException("socket");
                }
                if (host == null)
                {
                    throw new ArgumentNullException("host");
                }

                this.ConnectionID       = connectionID;
                this._socket            = socket;
                this._messageBufferSize = host.MessageBufferSize;
                this._host = host;

                try
                {
                    this.LocalEndPoint  = (IPEndPoint)socket.LocalEndPoint;
                    this.RemoteEndPoint = (IPEndPoint)socket.RemoteEndPoint;
                }
                catch (Exception ex) { Log.Trace.Error("get socket endPoint error.", ex); }

                //init send socketAsyncEventArgs
                this._saeSend = new SocketAsyncEventArgs();
                this._saeSend.SetBuffer(new byte[host.MessageBufferSize], 0, host.MessageBufferSize);
                this._saeSend.Completed += new EventHandler <SocketAsyncEventArgs>(this.SendAsyncCompleted);
                this._packetQueue        = new PacketQueue(this.SendPacketInternal);

                //init receive socketAsyncEventArgs
                this._saeReceive = new SocketAsyncEventArgs();
                this._saeReceive.SetBuffer(new byte[host.MessageBufferSize], 0, host.MessageBufferSize);
                this._saeReceive.Completed += new EventHandler <SocketAsyncEventArgs>(this.ReceiveAsyncCompleted);
            }