Esempio n. 1
0
            // Delegates
            /// <summary>
            /// Delegate which is called when a new connection is received
            /// </summary>
            /// <param name="asyncAccept"></param>
            private void AcceptConnectionDelegate(IAsyncResult asyncAccept)
            {
                // Accept the connection on a new socket
                Socket socket = mMainSocket.EndAccept(asyncAccept);

                // Assign the socket to a ServerWorker object:
                ServerWorker sw = new ServerWorker(socket);

                if (mWorkerSockets.Count >= MAX_CLIENTS)
                {
                    // We cannot accept the connection as we have reached our limit:
                    sw.SendData(ServerResponseCode.SERVICE_NOT_AVAILABLE);
                }
                else if (HaveLoggedInUser)
                {
                    // We can accept the connection but client will have to FORCE LOGIN to proceed:
                    sw.SendData(ServerResponseCode.BUSY);
                }
                else
                {
                    // We wish to accept the connection; let's get the user logged in (if need be) etc
                    sw.SendData(ServerResponseCode.HELLO);
                }

                // Release the main socket:
                AcceptConnections();
            }
Esempio n. 2
0
            // Delegates
            /// <summary>
            /// Delegate which is called when a new connection is received
            /// </summary>
            /// <param name="asyncAccept"></param>
            private void AcceptConnectionDelegate(IAsyncResult asyncAccept)
            {
                // Accept the connection on a new socket
                Socket socket = mMainSocket.EndAccept(asyncAccept);

                // Assign the socket to a ServerWorker object:
                ServerWorker sw = new ServerWorker(socket);

                if (mWorkerSockets.Count >= MAX_CLIENTS)
                    // We cannot accept the connection as we have reached our limit:
                    sw.SendData(ServerResponseCode.SERVICE_NOT_AVAILABLE);
                else if (HaveLoggedInUser)
                    // We can accept the connection but client will have to FORCE LOGIN to proceed:
                    sw.SendData(ServerResponseCode.BUSY);
                else
                {
                    // We wish to accept the connection; let's get the user logged in (if need be) etc
                    sw.SendData(ServerResponseCode.HELLO);
                }

                // Release the main socket:
                AcceptConnections();
            }