Пример #1
0
        // Send stage two: serialized NetworkMessage as ArraySegment<byte>
        internal override void Send(ArraySegment <byte> segment, int channelId = Channels.Reliable)
        {
            if (segment.Count == 0)
            {
                Debug.LogError("LocalConnection.SendBytes cannot send zero bytes");
                return;
            }

            // OnTransportData assumes batching.
            // so let's make a batch with proper timestamp prefix.
            Batcher batcher = GetBatchForChannelId(channelId);

            batcher.AddMessage(segment, NetworkTime.localTime);

            // flush it to the server's OnTransportData immediately.
            // local connection to server always invokes immediately.
            using (NetworkWriterPooled writer = NetworkWriterPool.Get())
            {
                // make a batch with our local time (double precision)
                if (batcher.GetBatch(writer))
                {
                    NetworkServer.OnTransportData(connectionId, writer.ToArraySegment(), channelId);
                }
                else
                {
                    Debug.LogError("Local connection failed to make batch. This should never happen.");
                }
            }
        }
        internal override void Send(ArraySegment <byte> segment, int channelId = Channels.Reliable)
        {
            if (segment.Count == 0)
            {
                Debug.LogError("LocalConnection.SendBytes cannot send zero bytes");
                return;
            }

            // handle the server's message directly
            NetworkServer.OnTransportData(connectionId, segment, channelId);
        }