void OnReceiveError(SocketRead read, System.Exception exception) { //Dev View Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error received: " + exception); Console.ResetColor(); }
private void OnReceive(IAsyncResult result) { try { if (result.IsCompleted) { int bytesRead = this.socket.EndReceive(result); if (bytesRead > 0) { byte[] read = new byte[bytesRead]; Array.Copy(this.buffer, 0, read, 0, bytesRead); this.readHandler(this, read); SocketRead.Begin(this.socket, this.readHandler, this.errorHandler); } else { // Disconnect } } } catch (Exception e) { if (this.errorHandler != null) { this.errorHandler(this, e); } } }
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); } }
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 OnReceive(SocketRead read, byte[] data) { try { var socketHandle = read.Socket.Handle.ToInt64(); var c = ResourcesManager.GetClient(socketHandle); c.DataStream.AddRange(data); Message p; while (c.TryGetPacket(out p)) { PacketManager.ProcessIncomingPacket(p); } } catch (Exception ex) { Debugger.WriteLine("Error when receiving packet from client : ", ex, 4, ConsoleColor.Red); } }
private static void OnReceive(SocketRead read, byte[] data) { try { var socketHandle = read.Socket.Handle.ToInt64(); var c = ResourcesManager.GetClient(socketHandle); c.DataStream.AddRange(data); Message p; while (c.TryGetPacket(out p)) { PacketManager.ProcessIncomingPacket(p); } } catch (Exception ex) { Debugger.WriteLine("[UCR] Exception thrown when processing incoming packet : ", ex); } }
void OnReceive(SocketRead read, byte[] data) { try { long socketHandle = read.Socket.Handle.ToInt64(); Client c = ResourcesManager.GetClient(socketHandle); //Ajoute les données au stream client c.DataStream.AddRange(data); Message p; while (c.TryGetPacket(out p)) { PacketManager.ProcessIncomingPacket(p); } } catch (Exception) { //Client may not exist anymore } }
void OnReceive(SocketRead read, byte[] data) { try { long socketHandle = read.Socket.Handle.ToInt64(); Client c = ResourcesManager.GetClient(socketHandle); //Ajoute les données au stream client c.DataStream.AddRange(data); Message p; while (c.TryGetPacket(out p)) { PacketManager.ProcessIncomingPacket(p); } } catch(Exception) { //Client may not exist anymore } }
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); }
private void OnReceive(IAsyncResult result) { try { if (result.IsCompleted) { int num = this.Socket.EndReceive(result); if (num > 0) { byte[] array = new byte[num]; Array.Copy(this.buffer, 0, array, 0, num); this.readHandler(this, array); SocketRead.Begin(this.Socket, this.readHandler, this.errorHandler); } } } catch (Exception exception) { if (this.errorHandler != null) { this.errorHandler(this, exception); } } }
private static void OnReceiveError(SocketRead read, Exception exception) { }
private void OnReceiveError(SocketRead read, Exception exception) { Debugger.WriteLine("Error received: " + exception, null, 5); }
void OnReceiveError(SocketRead read, System.Exception exception) { //Console.WriteLine("Error received: " + exception); }