/// Create a server instance. /// To start the server listening for connection requests /// call the Init method followed by Start method. /// <param name="numConnections">Maximum number of connections to be handled simultaneously.</param> /// <param name="receiveBufferSize">Buffer size to use for each socket I/O operation.</param> public Server(Int32 port, Int32 numConnections, Int32 receiveBufferSize, IPAddress subnet) { // Allocate buffers such that the maximum number of sockets can have one outstanding read and // write posted to the socket simultaneously . //When the event is signaled, the application uses the SocketAsyncEventArgs object //parameter to obtain the status of the completed asynchronous socket operation. this.port = port; this.numConnectedSockets = 0; this.maxNumConnections = numConnections; this.bufferManager = new BufferPool(receiveBufferSize * maxNumConnections * buffersPerSocket, receiveBufferSize); this.readWritePool = new SocketAsyncEventArgsPool(numConnections); this.semaphoreAcceptedClients = new SemaphoreSlim(numConnections, numConnections); listenerEventArgs = new SocketAsyncEventArgs(); listenerEventArgs.UserToken = port; // TBD RR: use this !!!! listenerEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(FinishClientAccept); this.subnet = subnet; this.subnetbytes = subnet.GetAddressBytes(); }
/// Create a server instance. /// To start the server listening for connection requests /// call the Init method followed by Start method. /// <param name="numConnections">Maximum number of connections to be handled simultaneously.</param> /// <param name="receiveBufferSize">Buffer size to use for each socket I/O operation.</param> public Server(Int32 port, Int32 numConnections, Int32 receiveBufferSize, IPAddress subnet) { // Allocate buffers such that the maximum number of sockets can have one outstanding read and // write posted to the socket simultaneously . //When the event is signaled, the application uses the SocketAsyncEventArgs object //parameter to obtain the status of the completed asynchronous socket operation. this.port = port; this.numConnectedSockets = 0; this.maxNumConnections = numConnections; this.bufferManager = new BufferPool(receiveBufferSize * maxNumConnections * buffersPerSocket, receiveBufferSize); this.readWritePool = new SocketAsyncEventArgsPool(numConnections); this.semaphoreAcceptedClients = new SemaphoreSlim(numConnections, numConnections); listenerEventArgs = new SocketAsyncEventArgs(); listenerEventArgs.UserToken = port; // TBD RR: use this !!!! listenerEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(FinishClientAccept); this.subnet = subnet; this.subnetbytes = subnet.GetAddressBytes(); }