Transports ========== A mod adds a transport, such as TCP/IP or HTTP, as a protocol. This in-process transport takes its calls from other threads of the game process. Its protocol names it, gives its settings, and creates its server: .. literalinclude:: /scripts/extending/transports/QueueTransport.lib.cs :language: csharp :start-at: [KRPCProtocol] :end-at: return new QueueServer (); :dedent: ``KRPC.Server.KRPCProtocol`` marks the class, which needs a public parameterless constructor. The game creates and registers it before it loads its settings, so a server of the protocol starts with the others. Each setting is a ``KRPC.Server.Setting``, and the server window draws a field for it by its kind. The id names the protocol in the settings file. Calls ----- Each call the transport takes is a ``KRPC.Server.Call``. It decodes its request on the game thread, and receives its response there: .. literalinclude:: /scripts/extending/transports/QueueTransport.lib.cs :language: csharp :start-at: sealed class QueuedCall :end-at: result.TrySetCanceled (); :dedent: ``Abort`` fails a call whose client ended before it completed. A request names its procedure by a ``ProcedureSignature``, from ``KRPC.Server.Transport.ServerCore.Services``. A transport with its own encoding reaches the object store and the structures through ``ServerCore``. ``AddObject`` gives the id of a class instance and ``GetObject`` the instance of an id, both on the game thread. ``Struct`` gives the structure with a type, with its fields. Clients ------- Each client queues its calls on a ``KRPC.Server.CallQueue``, which the server core reads. The queue completes each call with the response to its request: .. literalinclude:: /scripts/extending/transports/QueueTransport.lib.cs :language: csharp :start-at: public Task Call ( :end-at: return call.Result; :dedent: ``Enqueue`` may be called from any thread, and wakes the server's update. ``End`` aborts the calls queued and in flight. The server raises ``OnClientRequestingConnection`` for each new client, as the network servers do, so the player approves it in the same way: .. literalinclude:: /scripts/extending/transports/QueueTransport.lib.cs :language: csharp :start-at: public void Update () :end-at: client.Close (); :dedent: A client the server core ends has ``Connected`` false, and the next update raises ``OnClientDisconnected`` for it. .. note:: A breaking change to the transport API is a major change of the version of ``KRPC.Core``, which a mod checks through the assembly version.