private void OnClientConnect(IAsyncResult result) { try { Socket clientSocket = Socket.EndAccept(result); /* WebClient c = new WebClient(); * c.DownloadStringCompleted += * (sender, e) => * { * Console.WriteLine("[UCS] Client connected (" + * ((IPEndPoint) clientSocket.RemoteEndPoint).Address + ", " + e.Result.Trim() + * ")"); * }; * c.DownloadStringAsync( * new Uri("http://ipinfo.io/" + ((IPEndPoint) clientSocket.RemoteEndPoint).Address + "/country")); * */ Console.WriteLine("[UCS] Client connected (" + ((IPEndPoint)clientSocket.RemoteEndPoint).Address + ")"); ResourcesManager.AddClient(new Client(clientSocket), ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString()); SocketRead.Begin(clientSocket, OnReceive, OnReceiveError); Socket.BeginAccept(OnClientConnect, Socket); } catch (Exception e) { Debugger.WriteLine("[UCS] Exception when accepting incoming connection", e); } }
void OnClientConnect(IAsyncResult ar) { allDone.Set(); try { Socket listener = (Socket)ar.AsyncState; Socket clientSocket = listener.EndAccept(ar); _Logger.Print("[UCS] Player connected -> " + ((IPEndPoint)clientSocket.RemoteEndPoint).Address + "", Types.ERROR); ResourcesManager.AddClient(new Client(clientSocket), ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString()); SocketRead.Begin(clientSocket, OnReceive, OnReceiveError); } catch (Exception e) { } }
void OnClientConnect(IAsyncResult ar) { allDone.Set(); try { Socket listener = (Socket)ar.AsyncState; Socket clientSocket = listener.EndAccept(ar); Console.WriteLine("[UCS] Player connected " + ((IPEndPoint)clientSocket.RemoteEndPoint).Address + ""); ResourcesManager.AddClient(new Client(clientSocket), ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString()); SocketRead.Begin(clientSocket, OnReceive, OnReceiveError); } catch (Exception e) { //Debugger.WriteLine("[UCS] Exception when accepting incoming connection", e); } }