示例#1
0
        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}");
            }
        }
示例#2
0
        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();
        }
示例#3
0
 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);
 }