Skip to main content

Interface ISocket

Link between Mirage and the outside world

Syntax
public interface ISocket

Methods

Bind(IBindEndPoint)

Starts listens for data on an endPoint Used by Server to allow clients to connect

Declaration
void Bind(IBindEndPoint endPoint)
Parameters
TypeNameDescription
Mirage.SocketLayer.IBindEndPointendPointthe endPoint to listen on

Connect(IConnectEndPoint)

Sets up Socket ready to send data to endPoint as a client

Declaration
IConnectionHandle Connect(IConnectEndPoint endPoint)
Parameters
TypeNameDescription
Mirage.SocketLayer.IConnectEndPointendPointthe endPoint to connect to
Returns
TypeDescription
Mirage.SocketLayer.IConnectionHandlereturns the handle for the connection

Close()

Closes the socket, stops receiving messages from other peers

Declaration
void Close()

SetTickEvents(Int32, OnData, OnDisconnect)

Set events that will be used by . Will be called once when is set up with . The onData and onDisconnect events should only be invoked from within the method.

Declaration
void SetTickEvents(int maxPacketSize, OnData onData, OnDisconnect onDisconnect)
Parameters
TypeNameDescription
System.Int32maxPacketSize
Mirage.SocketLayer.OnDataonData
Mirage.SocketLayer.OnDisconnectonDisconnect

Tick()

Should invoke and events for any new data or disconnections. This method is called by once per frame.

Declaration
void Tick()

Flush()

Optional function, will call this after

Declaration
void Flush()

Poll()

Checks if a packet is available

Declaration
bool Poll()
Returns
TypeDescription
System.Booleantrue if there is atleast 1 packet to read

Receive(Span<Byte>, out IConnectionHandle)

Gets next packet Should be called after Poll

Implementation should check that incoming packet is within the size of buffer,
and make sure not to return bytesReceived above that size
Declaration
int Receive(Span<byte> outBuffer, out IConnectionHandle handle)
Parameters
TypeNameDescription
Span<System.Byte>outBuffer
Mirage.SocketLayer.IConnectionHandlehandle
Returns
TypeDescription
System.Int32length of packet, should not be above buffer length

Send(IConnectionHandle, ReadOnlySpan<Byte>)

Sends a packet to an endPoint Implementation should use length because packet is a buffer than may contain data from previous packets

Declaration
void Send(IConnectionHandle handle, ReadOnlySpan<byte> packet)
Parameters
TypeNameDescription
Mirage.SocketLayer.IConnectionHandlehandle
ReadOnlySpan<System.Byte>packetbuffer that contains the packet, starting at index 0