//------------------------------------------------------------------------------------------------------------------- //- 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); } }
//=================================================================================================================== //=================================================================================================================== //= 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(); }
public void Clear() { _clients = null; }