Skip to main content

ISocket

An interface in Root.Township, Alta.Networking.

The game's network socket: owns the list of Connections and sends messages over the transport. The live one is Socket.Current (a FakeSocket when offline); on a server it holds one connection per player.

Properties​

MemberWhat it is
int ConnectionCount { get; }Number of open connections.
IEnumerable<Connection> Connections { get; }All open connections.
ConnectionChannel DefaultChannel { get; set; }Channel given to new connections as their default.
bool IsServer { get; }True when this socket was opened as a server.
int OutgoingQueueSize { get; set; }Size of the transport's outgoing queue, updated each send.
ITransportSocket TransportSocket { get; }The low level transport socket underneath.

Events​

MemberWhat it is
event ConnectionEventHandler ConnectionCreatedRaised when a connection is added.
event ConnectionEventHandler ConnectionDestroyedRaised after a connection is removed and disposed.
event Action<ISocket> SocketDestroyedRaised when the socket is shut down.

Methods​

MemberWhat it is
Connection CreateConnection(ITransportConnection transportConnection, string ipAddress)Adds a connection, either wrapping an incoming transport connection or connecting out to an address and port (localhost means 127.0.0.1).
Connection CreateConnection(string ipAddress, int port)Adds a connection, either wrapping an incoming transport connection or connecting out to an address and port (localhost means 127.0.0.1).
void DestroyConnection(Connection connection, bool isFlushing = false)Removes and disposes a connection, optionally sending its queued packets first, then raises ConnectionDestroyed.
Connection GetConnection(int identifier)Finds a connection by its transport id, or null.
bool SendToAll(ConnectionChannel channel, MessageType type, SerializeConnectionMethod handler)Serialises a message once and sends it to every connection. Returns false if any send failed.
bool SendToPlayers(ConnectionChannel channel, MessageType type, SerializeConnectionMethod handler, IEnumerable<IPlayer> players)Serialises a message once (using the first player's connection) and sends it to each listed player.
void UpdateReceive()Processes each connection's queued messages, then reads new packets from the transport.
void UpdateSend()Flushes each connection's outgoing packet managers (rotating who goes first) and sends them.

Used in​

Members of other types that take, return or hold a ISocket: