2using System.Collections.Generic;
14 internal readonly Queue<NetworkWriterPooled> queue =
new Queue<NetworkWriterPooled>();
16 public override string address =>
"localhost";
19 bool connectedEventPending;
20 bool disconnectedEventPending;
21 internal void QueueConnectedEvent() => connectedEventPending =
true;
22 internal void QueueDisconnectedEvent() => disconnectedEventPending =
true;
25 internal override void Send(ArraySegment<byte> segment,
int channelId =
Channels.Reliable)
27 if (segment.Count == 0)
29 Debug.LogError(
"LocalConnection.SendBytes cannot send zero bytes");
35 Batcher batcher = GetBatchForChannelId(channelId);
43 if (batcher.GetBatch(writer))
47 else Debug.LogError(
"Local connection failed to make batch. This should never happen.");
51 internal override void Update()
56 if (connectedEventPending)
58 connectedEventPending =
false;
63 while (queue.Count > 0)
77 if (batcher.GetBatch(batchWriter))
87 if (disconnectedEventPending)
89 disconnectedEventPending =
false;
95 internal void DisconnectInternal()
101 NetworkClient.ready =
false;
107 connectionToClient.DisconnectInternal();
108 DisconnectInternal();
124 internal override bool IsAlive(
float timeout) =>
true;
override void Disconnect()
Disconnects this connection.
NetworkClient with connection to server.
readonly int connectionId
Unique identifier for this connection that is assigned by the transport layer.
bool isReady
A server connection is ready after joining the game world.
NetworkServer handles remote connections and has a local connection for a local client.
Synchronizes server time to clients.
ArraySegment< byte > ToArraySegment()
Returns allocation-free ArraySegment until 'Position'.
Pool of NetworkWriters to avoid allocations.
static void Return(NetworkWriterPooled writer)
Return a writer to the pool.
static NetworkWriterPooled Get()
Get a writer from the pool. Creates new one if pool is empty.
Pooled NetworkWriter, automatically returned to pool when using 'using'