public void SendOne(int connectionId, int channelId, ArraySegment <byte> segment) { if (server == null) { logger.LogWarning("LiteNet SV: can't send because not started yet."); return; } if (connections.TryGetValue(connectionId, out NetPeer peer)) { try { DeliveryMethod deliveryMethod = LiteNetLibTransportUtils.ConvertChannel(channelId); peer.Send(segment.Array, segment.Offset, segment.Count, deliveryMethod); } catch (TooBigPacketException exception) { if (logger.WarnEnabled()) { logger.LogWarning($"LiteNet SV: send failed for connectionId={connectionId} reason={exception}"); } } } else if (logger.WarnEnabled()) { logger.LogWarning($"LiteNet SV: invalid connectionId={connectionId}"); } }
private void Listener_NetworkReceiveEvent(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod) { if (logger.LogEnabled()) { logger.Log($"LiteNet CL received {reader.AvailableBytes} bytes. method={deliveryMethod}"); } int mirrorChannel = LiteNetLibTransportUtils.ConvertChannel(deliveryMethod); onData?.Invoke(reader.GetRemainingBytesSegment(), mirrorChannel); reader.Recycle(); }
public bool Send(int channelId, ArraySegment <byte> segment) { if (client != null && client.FirstPeer != null) { try { // convert Mirror channel to LiteNetLib channel & send DeliveryMethod deliveryMethod = LiteNetLibTransportUtils.ConvertChannel(channelId); client.FirstPeer.Send(segment.Array, segment.Offset, segment.Count, deliveryMethod); return(true); } catch (TooBigPacketException exception) { if (logger.WarnEnabled()) { logger.LogWarning($"LiteNet CL: send failed. reason={exception}"); } return(false); } } return(false); }