/// <summary> /// This method is called when new client connecting to socket /// </summary> /// <param name="Result"></param> private void acceptConnection(IAsyncResult Result) { // restore the socket object Socket server = (Socket)Result.AsyncState; try { // get socket of client connected Socket client = server.EndAccept(Result); // one thread per time lock (ThreadLocker.sync("ServerListen::acceptConnection")) { nextClientId++; } if (UnauthenticatedTable.get(((IPEndPoint)client.RemoteEndPoint).Address.ToString()) >= ServerController.config.MaxUnauthenticatedAccept) { client.Close(); } else { // we add the new connected client to the listener channel new ClientListen(client, nextClientId); } } catch (Exception ex) { DarkKnight.Utils.Log.Write("A new client connected generate a error and not accepted: \n" + ex.Message + " - " + ex.StackTrace, Utils.LogLevel.ERROR); } finally { // release to accept more connections asynchronous server.BeginAccept(new AsyncCallback(acceptConnection), server); } }
public static void add(Client client) { UnauthenticatedTable.add(client.IPAddress.ToString()); }