private void Dispose(bool Disposing) { if (!this.mDisposed && Disposing) { this.mDisposed = true; try { base.Shutdown(SocketShutdown.Both); base.Close(); base.Dispose(); } catch { } Array.Clear(this.mDataBuffer, 0, this.mDataBuffer.Length); this.mDataBuffer = null; this.mDataReceivedCallback = null; this.mRouteReceivedDataCallback = null; PhoenixEnvironment.GetConnectionManager().DropConnection(this.mID); TcpAuthorization.FreeConnection(this.mIP); if (PhoenixEnvironment.GetConfig().data["emu.messages.connections"] == "1") { Console.WriteLine(string.Concat(new object[] { ">> Connection Dropped [", this.mID, "] from [", this.ipAddress, "]" })); } } }
public TcpConnectionListener(string LocalIp, int Port, TcpConnectionManager Manager) { IPEndPoint localEP = new IPEndPoint(IPAddress.Any, Port); this.Listener.Bind(localEP); this.Listener.Listen(1000); this.ConnectionReqCallback = new AsyncCallback(this.ConnectionRequest); this.Manager = Manager; TcpAuthorization.SetupTcpAuthorization(20000); Logging.WriteLine("Listening for connections on port: " + Port); }
private void ConnectionRequest(IAsyncResult iAr) { if (this.IsListening) { try { int preconnID = this.Manager.GenerateConnectionID(); if (preconnID > -1) { Socket sock = ((Socket)iAr.AsyncState).EndAccept(iAr); if (TcpAuthorization.CheckConnection(sock)) { this.Manager.HandleNewConnection(sock.DuplicateAndClose(this.mSystraID), preconnID); } else { try { sock.Dispose(); sock.Close(); } catch { } } } } catch (Exception exception) { Logging.LogException("[TCPListener.OnRequest]: Could not handle new connection request: " + exception.ToString()); } finally { this.WaitForNextConnection(); } } }