void OnClientConnect(System.IAsyncResult result) { try { Socket clientSocket = m_vServerSocket.EndAccept(result); Debugger.WriteLine("[M] Client connected (" + ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString() + ":" + ((IPEndPoint)clientSocket.RemoteEndPoint).Port.ToString() + ")"); ResourcesManager.AddClient(new Client(clientSocket)); SocketRead.Begin(clientSocket, OnReceive, OnReceiveError); } catch (System.Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Exception when accepting incoming connection: " + e); Console.ResetColor(); } try { m_vServerSocket.BeginAccept(new System.AsyncCallback(OnClientConnect), m_vServerSocket); } catch (System.Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Exception when starting new accept process: " + e); Console.ResetColor(); } }
private void OnClientConnect(IAsyncResult result) { try { var clientSocket = Socket.EndAccept(result); ResourcesManager.AddClient(new Client(clientSocket), ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString()); SocketRead.Begin(clientSocket, OnReceive, OnReceiveError); Console.WriteLine("[UCS] Client connected (" + ((IPEndPoint)clientSocket.RemoteEndPoint).Address + ":" + ((IPEndPoint)clientSocket.RemoteEndPoint).Port + ")"); } catch (Exception e) { Console.WriteLine("[UCS] Exception when accepting incoming connection: " + e); } try { Socket.BeginAccept(OnClientConnect, Socket); } catch (Exception e) { Console.WriteLine("[UCS] Exception when starting new accept process: " + e); } }
private void AcceptCallback(IAsyncResult ar) { try { AllDone.Set(); Socket _Listener = (Socket)ar.AsyncState; Socket _Handler = _Listener.EndAccept(ar); Logger.Write("New TCP Client connected -> " + ((IPEndPoint)_Handler.RemoteEndPoint).Address); if (!ConnectionBlocker.IsAddressBanned(((IPEndPoint)_Handler.RemoteEndPoint).Address.ToString())) { ResourcesManager.AddClient(_Handler); new Reader(_Handler, this.ProcessPacket); } else { Disconnect(_Handler); ResourcesManager.DropClient(_Handler.Handle); } } catch (Exception) { } }
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) { } }
internal void ProcessAccept(SocketAsyncEventArgs AsyncEvent) { Socket Socket = AsyncEvent.AcceptSocket; if (Socket.Connected && AsyncEvent.SocketError == SocketError.Success) { if (!ConnectionBlocker.Banned_IPs.Contains(((IPEndPoint)Socket.RemoteEndPoint).Address.ToString())) { Logger.Write($"New client connected -> {((IPEndPoint)Socket.RemoteEndPoint).Address}"); SocketAsyncEventArgs ReadEvent = this.ReadPool.Dequeue(); if (ReadEvent != null) { Device device = new Device(Socket) { IPAddress = ((IPEndPoint)Socket.RemoteEndPoint).Address.ToString() }; Token Token = new Token(ReadEvent, device); Interlocked.Increment(ref this.ConnectedSockets); ResourcesManager.AddClient(device); Task.Run(() => { try { if (!Socket.ReceiveAsync(ReadEvent)) { this.ProcessReceive(ReadEvent); } } catch (Exception) { this.Disconnect(ReadEvent); } }); } } } else { Logger.Write("Not connected or error at ProcessAccept."); Socket.Close(5); } this.StartAccept(AsyncEvent); }
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); } }
private static void ProcessAccept(SocketAsyncEventArgs e, bool startNew) { var acceptSocket = e.AcceptSocket; if (e.SocketError != SocketError.Success) { Logger.Error($"Failed to accept new socket: {e.SocketError}."); Drop(e); // Get a new args from pool, since we dropped the previous one. e = GetArgs(); } else { try { if (Constants.Verbosity > 3) { Logger.Say($"Accepted connection at {acceptSocket.RemoteEndPoint}."); } var client = new Device(acceptSocket); // Register the client in the ResourceManager. ResourcesManager.AddClient(client); var args = GetArgs(); var buffer = GetBuffer(); args.UserToken = client; args.SetBuffer(buffer, 0, buffer.Length); StartReceive(args); } catch (Exception ex) { ExceptionLogger.Log(ex, "Exception while processing accept"); } } // Clean up for reuse. e.AcceptSocket = null; if (startNew) { StartAccept(e); } }
private void AcceptCallback(IAsyncResult ar) { try { AllDone.Set(); Socket listener = (Socket)ar.AsyncState; Socket handler = listener.EndAccept(ar); Say("New TCP Client connected -> " + ((IPEndPoint)handler.RemoteEndPoint).Address); Logger.Write("New TCP Client connected -> " + ((IPEndPoint)handler.RemoteEndPoint).Address); ResourcesManager.AddClient(handler); new Reader(handler, ProcessPacket); } catch (Exception) { } }
private static void ProcessAccept(SocketAsyncEventArgs e, bool startNew) { var acceptSocket = e.AcceptSocket; if (e.SocketError != SocketError.Success) { KillSocket(acceptSocket); Logger.Say($"Failed to accept new socket: {e.SocketError}."); } else { try { Logger.Say($"Accepted connection at {acceptSocket.RemoteEndPoint}."); var client = new Client(acceptSocket); // Let UCS know we've got a client. ResourcesManager.AddClient(client); var args = GetArgs(); var buffer = GetBuffer(); args.UserToken = client; args.SetBuffer(buffer, 0, buffer.Length); StartReceive(args); } catch (ObjectDisposedException) { Recycle(e); } catch (Exception ex) { ExceptionLogger.Log(ex, "Exception while processing accept"); } } // Clean up for reuse. e.AcceptSocket = null; if (startNew) { StartAccept(e); } }
private void ProcessAccept(SocketAsyncEventArgs args) { if (args.SocketError != SocketError.Success) { StartAccept(); // start to accept as soon as possible ProcessBadAccept(args); return; } StartAccept(); // start to accept as soon as possible var connection = args.AcceptSocket; var remoteEndPoint = (IPEndPoint)connection.RemoteEndPoint; ResourcesManager.AddClient(new Client(connection)); SocketRead.Begin(connection, OnReceive, OnReceiveError); Console.WriteLine("Client connected ({0}:{1})", remoteEndPoint.Address, remoteEndPoint.Port); args.AcceptSocket = null; _acceptPool.Push(args); }
//public static void Disconnect(Socket _Handler) //{ // try // { // _Handler.Shutdown(SocketShutdown.Both); // _Handler.Close(); // } // catch (Exception ex) // { // UCS.Core.Debug.Write(ex.Message); // } //} private void AcceptCallback(IAsyncResult _Ar) { try { Wait.Set(); Socket _Listener = (Socket)_Ar.AsyncState; Socket _Handler = _Listener.EndAccept(_Ar); Debug.Write("Hello from " + _Handler.RemoteEndPoint + "."); ResourcesManager.AddClient(new Client(_Handler)); new Reader(_Handler, this.ProcessPacket); _Listener.BeginAccept(this.AcceptCallback, _Listener); } catch (Exception ex) { UCS.Core.Debug.Write(ex.Message); ////Console.WriteLine(ex.Message); } }