Vixen
02b45cc4
csharp
public sealed class UdpTransport

The transport with a socket in it: four channels, retransmission, reassembly and timeouts, over datagrams that arrive when they feel like it and sometimes not at all.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Everything the layers above rely on — that a Reliable payload arrives once and in order, that a Sequenced one is never delivered after a newer one, that a 64 KiB payload arrives whole — is built here out of a medium that promises none of it. The conformance suite is what says it worked: this transport is held to exactly the same tests as the in-process one, which is the point of having written them against the interface.

The socket is behind a seam. Sequencing, retransmission and reassembly are the parts that are subtle, and they are tested over an in-memory bus where time is a parameter and every run is the same run. The socket adapter under it is thin enough to read.

Time is a parameter here too. Retransmission timeouts, keep-alives and connection timeouts are all spent against the clock Poll advances, so a test that wants to watch a connection time out does it in a loop rather than in ten seconds.

Fields and properties (7)

  • public TransportCapabilities Capabilities

    What this transport can carry, and what it will not promise.

  • public TransportState ServerState

    Whether the server half is listening.

  • public TransportState ClientState

    Whether the client half is connected.

  • public int ConnectionCount

    How many clients the server half has.

  • public EndPoint? ListeningOn

    Where the server half is bound, once it is listening.

  • public long RejectedDatagramCount

    Datagrams that were not a packet this transport understands.

  • public long RetransmitCount

    Datagrams sent again because no acknowledgement came for them.

Methods (10)

  • public UdpTransport(IDatagramSocketFactory factory, UdpTransportOptions? options = null)

    Creates a transport.

  • public void StartServer()

    Starts listening. Where — a port, an address, a relay — was fixed when the transport was constructed, which is what keeps this interface free of anything socket-shaped.

  • public void StopServer()

    Stops listening and disconnects everyone, reporting ServerStopped to both sides. Does nothing if the server half is already stopped.

  • public void StartClient()

    Begins connecting. Completion is reported to OnConnected on a later Poll, or refusal to OnDisconnected — never inline, so the caller has one code path for "connected in a microsecond over loopback" and "connected in 90 ms over the Atlantic".

  • public void StopClient()

    Disconnects the client half, reporting Requested to this side and RemoteRequested to the server. Does nothing if the client half is already stopped.

  • public void Disconnect(ConnectionId connection)

    Closes one connection from the server side, reporting Requested here and Kicked there. Does nothing if the connection is not one of ours.

  • public void SendToClient(ConnectionId connection, ReadOnlySpan<byte> payload, Channel channel)

    Sends to one connected client. Does nothing if the connection is not ours.

  • public void SendToServer(ReadOnlySpan<byte> payload, Channel channel)

    Sends to the server. Does nothing if the client half is not connected.

  • public void Poll(TimeSpan elapsed, ITransportEvents events)

    Advances the transport by and reports everything that has happened since the last call, in the order it happened, to .

  • public void Dispose()

    Stops both halves and closes the sockets.

Used by (8)

  • NetworkMatchMultiplayer
  • PeerVoiceChat
  • ProgramVoiceChat
  • RealSocketTestsVixen.Net.Transport.Udp.Tests
  • UdpReliabilityTestsVixen.Net.Transport.Udp.Tests
  • UdpTransportConformanceTestsVixen.Net.Transport.Udp.Tests
  • UdpTransportTargetVixen.Net.Fuzz
  • RealmVixen.Live.Realm