Mirror Networking
LocalConnectionToClient.cs
1using System;
2
3namespace Mirror
4{
5 // a server's connection TO a LocalClient.
6 // sending messages on this connection causes the client's handler function to be invoked directly
8 {
9 internal LocalConnectionToServer connectionToServer;
10
11 public LocalConnectionToClient() : base(LocalConnectionId) {}
12
13 public override string address => "localhost";
14
15 // Send stage two: serialized NetworkMessage as ArraySegment<byte>
16 internal override void Send(ArraySegment<byte> segment, int channelId = Channels.Reliable)
17 {
18 // get a writer to copy the message into since the segment is only
19 // valid until returning.
20 // => pooled writer will be returned to pool when dequeuing.
21 // => WriteBytes instead of WriteArraySegment because the latter
22 // includes a 4 bytes header. we just want to write raw.
23 //Debug.Log($"Enqueue {BitConverter.ToString(segment.Array, segment.Offset, segment.Count)}");
25 writer.WriteBytes(segment.Array, segment.Offset, segment.Count);
26 connectionToServer.queue.Enqueue(writer);
27 }
28
29 // true because local connections never timeout
30 internal override bool IsAlive(float timeout) => true;
31
32 internal void DisconnectInternal()
33 {
34 // set not ready and handle clientscene disconnect in any case
35 // (might be client or host mode here)
36 isReady = false;
37 RemoveFromObservingsObservers();
38 }
39
41 public override void Disconnect()
42 {
43 DisconnectInternal();
44 connectionToServer.DisconnectInternal();
45 }
46 }
47}
override void Disconnect()
Disconnects this connection.
bool isReady
A server connection is ready after joining the game world.
Pool of NetworkWriters to avoid allocations.
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'