public static async Task SendPacketsAsync(this IBroadcastable channelGroup, IEnumerable <IPacket> packets, IChannelMatcher?matcher) { var packetDefinitions = (packets as IPacket[] ?? packets).Where(c => c != null).ToArray(); if (packetDefinitions.Any()) { Parallel.ForEach(packets, packet => channelGroup.LastPackets.Enqueue(packet)); Parallel.For(0, channelGroup.LastPackets.Count - channelGroup.MaxPacketsBuffer, (_, __) => channelGroup.LastPackets.TryDequeue(out var ___)); if (channelGroup.Sessions == null) { return; } await channelGroup.Sessions.WriteAndFlushAsync(packetDefinitions).ConfigureAwait(false); if (matcher == null) { await channelGroup.Sessions.WriteAndFlushAsync(packetDefinitions).ConfigureAwait(false); } else { await channelGroup.Sessions.WriteAndFlushAsync(packetDefinitions, matcher).ConfigureAwait(false); } } }
public static void SendPackets(this IBroadcastable channelGroup, IEnumerable <IPacket> packets, IChannelMatcher matcher) { var packetDefinitions = (packets as IPacket[] ?? packets.ToArray()).Where(c => c != null); if (packetDefinitions.Any()) { Parallel.ForEach(packets, packet => channelGroup.LastPackets.Enqueue(packet)); Parallel.For(0, channelGroup.LastPackets.Count - maxPacketsBuffer, (_, __) => channelGroup.LastPackets.TryDequeue(out var ___)); channelGroup.Sessions?.WriteAndFlushAsync(packetDefinitions); if (matcher == null) { channelGroup.Sessions?.WriteAndFlushAsync(packetDefinitions); } else { channelGroup.Sessions?.WriteAndFlushAsync(packetDefinitions, matcher); } } }
private void Start() { allLogsRequestion = GetComponent <ICallbackRequestable <IReadOnlyList <PieceMoveData> > >(); retransmissionRequestion = GetComponent <ICallbackRequestable <PieceMoveData> >(); pieceMoveDataBroadcaster = GetComponent <IBroadcastable <PieceMoveData> >(); if (isServer) { allLogsRequestion.InitializeOnServer(serverContainer); retransmissionRequestion.InitializeOnServer(serverContainer); } if (isClient) { clientId = serverContainer.ResisterClient(netIdentity); allLogsRequestion.InitializeOnClient(clientId); retransmissionRequestion.InitializeOnClient(clientId); pieceMoveDataBroadcaster.OnRecieved.TakeUntilDestroy(this).Subscribe(onRecievedMoveData); } }
public static void SendPackets(this IBroadcastable channelGroup, IEnumerable <IPacket> packets) { channelGroup.SendPackets(packets, null); }
public static void SendPacket(this IBroadcastable channelGroup, IPacket packet, IChannelMatcher matcher) { channelGroup.SendPackets(new[] { packet }, matcher); }
public static void SendPacket(this IBroadcastable channelGroup, IPacket packet) { channelGroup.SendPackets(new[] { packet }); }
public static Task SendPacketsAsync(this IBroadcastable channelGroup, IEnumerable <IPacket> packets) { return(channelGroup.SendPacketsAsync(packets, null)); }
public static Task SendPacketAsync(this IBroadcastable channelGroup, IPacket packet, IChannelMatcher matcher) { return(channelGroup.SendPacketsAsync(new[] { packet }, matcher)); }
public static Task SendPacketAsync(this IBroadcastable channelGroup, IPacket packet) { return(channelGroup.SendPacketsAsync(new[] { packet })); }