protected void SendTo(EndPoint endPoint, PacketType packetType, Channel channel, ReadOnlySpan <byte> payload) { if (!remotes.TryGetValue(endPoint, out RUDPRemoteClient <T> client)) { client = new RUDPRemoteClient <T> (this, endPoint); remotes.TryAdd(endPoint, client); } remotes[endPoint].QueueOutgoing(endPoint, packetType, channel, payload); }
void ReadSocket() { RUDPRemoteClient <T> client; try { while (!tokenSource.IsCancellationRequested) { foreach (var incoming in socket.RecievedPackets.GetConsumingEnumerable(tokenSource.Token)) { if (!remotes.TryGetValue(incoming.remote, out client)) { client = new RUDPRemoteClient <T> (this, incoming.remote); remotes[incoming.remote] = client; } client.QueueIncoming(incoming.remote, incoming.data); } } } catch (Exception ex) { } }