Пример #1
0
 protected virtual SocketClient AcceptedSocketClient(SocketServer socketServer,
     Socket clientSocket, string ipAddress, int port,
     int sizeOfRawBuffer, object userArg, MessageEventHandler messageHandler,
     CloseEventHandler closeHandler, ErrorEventHandler errorHandler)
 {
     return new SocketClient(socketServer, clientSocket,
         ipAddress, port, sizeOfRawBuffer, userArg, messageHandler,
         closeHandler, errorHandler);
 }
Пример #2
0
        /// <summary> Constructor for SocketServer Suppport </summary>
        /// <param name="socketServer"> A Reference to the parent SocketServer </param>
        /// <param name="clientSocket"> The Socket object we are encapsulating </param>
        /// <param name="socketListArray"> The index of the SocketServer Socket List Array </param>
        /// <param name="ipAddress"> The IpAddress of the remote server </param>
        /// <param name="port"> The Port of the remote server </param>
        /// <param name="messageHandler"> Reference to the user defined message handler function </param>
        /// <param name="closeHandler"> Reference to the user defined close handler function </param>
        /// <param name="errorHandler"> Reference to the user defined error handler function </param>
        /// <param name="sizeOfRawBuffer"> The size of the raw buffer </param>
        /// <param name="userArg"> A Reference to the Users arguments </param>
        public SocketClient(SocketServer socketServer, Socket clientSocket,
            string ipAddress, int port, int sizeOfRawBuffer,
            object userArg, MessageEventHandler messageHandler, CloseEventHandler closeHandler,
            ErrorEventHandler errorHandler)
            : this(sizeOfRawBuffer, userArg, messageHandler, closeHandler, errorHandler)
        {

            // Set reference to SocketServer
            this.socketServer = socketServer;

            // Init the socket references
            this.clientSocket = clientSocket;

            // Set the Ipaddress and Port
            this.ipAddress = ipAddress;
            this.port = port;

            // Init the NetworkStream reference
            this.networkStream = new NetworkStream(this.clientSocket);

            // Set these socket options
            this.clientSocket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket,
                System.Net.Sockets.SocketOptionName.ReceiveBuffer, this.receiveBufferSize);
            this.clientSocket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket,
                System.Net.Sockets.SocketOptionName.SendBuffer, this.sendBufferSize);
            this.clientSocket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket,
                System.Net.Sockets.SocketOptionName.DontLinger, 1);
            this.clientSocket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Tcp,
                System.Net.Sockets.SocketOptionName.NoDelay, 1);

            // Wait for a message
            Receive();
        }