Ejemplo n.º 1
0
        //-------------------------------------------------------------------------------------------------------------------
        //-         MESSAGING                                                                                               -
        //-------------------------------------------------------------------------------------------------------------------

        #region -=[- MESSAGING -]=-

        /// <summary>
        /// Sends a message to a given client
        /// </summary>
        /// <param name="pMessage">Raw-Message to be sent</param>
        /// <param name="pSocket">Client-Socket</param>
        public void SendToClient(string pMessage, Socket pSocket)
        {
            if (pSocket != null && LClients.Authenticated(pSocket))
            {
                Debug($"Queueing message for {pSocket.GetHashCode()}: {pMessage}", DebugParams);
                OutgoingInstructions.Add(pMessage, pSocket);
            }
        }
Ejemplo n.º 2
0
        //===================================================================================================================
        //===================================================================================================================
        //=         CALLBACK METHODS                                                                                        =
        //===================================================================================================================
        //===================================================================================================================

        #region -=[- CALLBACK METHODS -]=-

        /// <summary>
        /// Gets called when a new client connects.
        /// </summary>
        /// <param name="AR"></param>
        private void OnClientAccept(IAsyncResult AR)
        {
            Debug($"New client connected!", DebugParams);

            // Accept the client socket and add it to the socket-list
            Socket clientSocket = ServerSocket.EndAccept(AR);

            LClients.Add(new NetComClientData(clientSocket));
            clientSocket.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, new AsyncCallback(OnClientReceive), clientSocket);

            // Re-Open the server-socket for further connections
            Start();
        }
Ejemplo n.º 3
0
 public void Clear()
 {
     _clients = null;
 }