static void Main(string[] args) { Log.Init("proxy"); waiting = new List <Connection>(); Log.Trace("Main", "Connecting to Database"); if (Database.Database.Init() == false) { while (true) { Thread.Sleep(1); } } Log.Debug("Main", "Connected to database sucesfull"); Log.Trace("Main", "Reseting Solar Systems' status"); Log.Trace("Main", "Starting listener on port 26000"); listener = new TCPSocket(26000, false); if (listener.Listen(int.MaxValue) == false) { Log.Error("Main", "Cannot listen on port 26000"); while (true) { ; } } Log.Debug("Main", "Listening on port 26000"); LoginQueue.Start(); // Add two nodes to the NodeManager NodeManager.AddNode(null); NodeManager.AddNode(null); while (true) { Thread.Sleep(1); TCPSocket con = listener.Accept(); if (con != null) { Connection tmp = new Connection(con); tmp.Start(); waiting.Add(tmp); } } }
/// <summary> /// 监听 /// </summary> private void ListenConnecting() { while (Flag_Listen) // 持续不断的监听客户端的连接请求; { Socket sokConnection = TCPSocket.Accept(); // 一旦监听到一个客户端的请求,就返回一个与该客户端通信的 套接字; // 将与客户端连接的 套接字 对象添加到集合中; string str_EndPoint = sokConnection.RemoteEndPoint.ToString(); TCPSession myTCPSession = new TCPSession() { Socket = sokConnection }; //创建线程接收数据 Thread th_ReceiveData = new Thread(ReceiveData); th_ReceiveData.IsBackground = true; th_ReceiveData.Start(myTCPSession); //把线程及客户连接加入字典 Dic_ClientSession.Add(str_EndPoint, myTCPSession); Dic_ClientThread.Add(str_EndPoint, th_ReceiveData); Thread.Sleep(200); } }
static void Main(string[] args) { Log.Init("packet-editor"); Log.Info("Main", "Starting listening socket"); socket = new TCPSocket(26000, false); if (socket.Listen(5) == false) { Log.Error("Main", "Cannot start listening socket on port 26000."); Log.Info("Main", "You should have your EVEmu server working on port 25999"); Log.Info("Main", "and port 26000 free of any server."); while (true) { Thread.Sleep(1); } } Log.Info("Main", "Listening socket started succesful"); while (true) { Thread.Sleep(1); while (clientList.Count > 0) { Thread.Sleep(10); } TCPSocket client = socket.Accept(); if (client != null) { clientList.Add(new Client.Client(client)); Log.Debug("Main", "Incoming connection, waiting until it finishes"); } } }
public void StartListening(int incomingBuffer = 1000) { String prt = m_port.ToString(); SByte[] sprt = new SByte[prt.Length]; for (int i = 0; i < prt.Length; ++i) { sprt[i] = (sbyte)prt[i]; } unsafe { fixed(SByte *ppp = sprt) { m_sock = new TCPSocket(ppp); } } ThreadPool.SetMaxThreads(40, 40); ThreadPool.SetMinThreads(40, 40); if (false == m_sock.InError()) { m_sock.StartListening(); } while (m_sock.Accept()) { if (true == m_sock.InError()) { continue; } UInt32 handler = m_sock.ReturnClientSocket(); var ThreadMain = System.Diagnostics.Stopwatch.StartNew(); //ThreadPool.QueueUserWorkItem(Socket.StarterFunction, handler); ThreadPool.QueueUserWorkItem(HttpStreamReader.ListenSocketHandler, handler); ThreadMain.Stop(); } // Create a TCP/IP socket. //m_listeningSocket = new SystemSocket(m_ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); // Bind the socket to the local endpoint and listen for incoming connections. /*try * { * m_listeningSocket.Bind(m_ipEndPoint); * m_listeningSocket.Listen(incomingBuffer); * * ThreadPool.SetMaxThreads(40, 40); * ThreadPool.SetMinThreads(40, 40); * * // Start listening for connections. * while (true) * { * // Program is suspended while waiting for an incoming connection. * SystemSocket handler = m_listeningSocket.Accept(); * System.Console.WriteLine(handler.Handle); * * var ThreadMain = System.Diagnostics.Stopwatch.StartNew(); * //ThreadPool.QueueUserWorkItem(Socket.StarterFunction, handler); * ThreadPool.QueueUserWorkItem(HttpStreamReader.ListenSocketHandler, handler); * ThreadMain.Stop(); * System.Console.WriteLine("Request Time " + ThreadMain.ElapsedMilliseconds); * * //log * //EndPoint endpt = handler.LocalEndPoint; * //long result = IPGlobalProperties.GetIPGlobalProperties() * // .GetTcpIPv4Statistics() * // .CurrentConnections; * //System.Console.WriteLine(result); * * } * * } * catch (Exception e) * { * Console.WriteLine(e.ToString()); * Environment.Exit(-1); * }*/ }