private void TryToRecieve(EndPointId identityId, TcpClient client, string ip, int port) { PacketManager packetManager = new PacketManager(); while (true) { byte[] b = new byte[1024 * 8]; int i = 0; try { i = client.GetStream().Read(b, 0, b.Length); } catch { ConnectionLostRaise(identityId, client); return; } if (Encoding.UTF8.GetString(b, 0, i) == "") { continue; } object[] packets = packetManager.AddStream(b, i, packetSplitter); object[][] packetsArgs = new object[packets.Length][]; for (int j = 0; j < packetsArgs.Length; j++) { packetsArgs[j] = packets[j].ToString().Split(argSplitter); } OnReceivedEvent?.Invoke(packetsArgs, identityId, new SocketInfo(ip, port, NetworkInterfaceType.TCP)); } }
private void TryToRecieve() { PacketManager packetManager = new PacketManager(); while (isConnected) { if (stream == null) { return; } try { byte[] b = new byte[1024 * 8]; int i = stream.Read(b, 0, b.Length); string[] packets = packetManager.AddStream(b, i, packetSplitter); string[][] packetsArgs = new string[packets.Length][]; for (int j = 0; j < packetsArgs.Length; j++) { packetsArgs[j] = packets[j].Split(argSplitter); } OnReceivedEvent?.Invoke(packetsArgs, ServerIp, ServerPort); } catch (Exception e) { Console.WriteLine(e); ConnectionLostRaise(); break; } } }
private void TryToRecieveLobbyInfo() { PacketManager packetManager = new PacketManager(); while (true) { if (lobbyInfoStream == null) { return; } try { byte[] b = new byte[1024 * 8]; int i = lobbyInfoStream.Read(b, 0, b.Length); object[] packets = packetManager.AddStream(b, i, packetSplitter); object[][] packetsArgs = new object[packets.Length][]; for (int j = 0; j < packetsArgs.Length; j++) { packetsArgs[j] = packets[j].ToString().Split(argSplitter); } OnReceivedEvent?.Invoke(packetsArgs, ServerIp, ServerPort); } catch (Exception) { break; } } }
private void RaiseOnReceive(DataReceivedArgs args) { try { _lastExchangeTime = Environment.TickCount; OnReceivedEvent?.Invoke(args); } catch (Exception) { } }
private void TryToReceive() { while (isConnected) { try { object arg = Encoding.Unicode.GetString(client.Receive(ref server)); object[] args; args = arg.ToString().Split(argSplitter); OnReceivedEvent?.Invoke(args, server.Address.ToString(), server.Port); } catch (Exception e) { ConnectionLostRaise(); Console.WriteLine(e); break; } } }
private void TryToReceive() { IPEndPoint remoteIp = new IPEndPoint(IPAddress.Any, port); while (true) { try { dataReceived = server.Receive(ref remoteIp); object arg = Encoding.Unicode.GetString(dataReceived); object[] args; args = arg.ToString().Split(argSplitter); OnReceivedEvent?.Invoke(args, remoteIp.Address.ToString(), remoteIp.Port); } catch (Exception e) { OnClientDisconnectedEvent?.Invoke(remoteIp.Address.ToString(), remoteIp.Port); Console.WriteLine(e); } } }
internal void InvokeReceivedEvent(ReceivedEventArgs args) { OnReceivedEvent?.Invoke(this, args); }
public Task InvokeReceivedEvent(string eventName, ResponseArgs args) { OnReceivedEvent?.Invoke(eventName, args); return(Task.CompletedTask); }
private void ReceiveHandler(string eventName, ResponseArgs args) => OnReceivedEvent?.Invoke(eventName, args);