Skip to main content

Interface ISocket

Link between Mirage and the outside world

Syntax
public interface ISocket

Methods

Bind(IEndPoint)

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

Declaration
void Bind(IEndPoint endPoint)
Parameters
TypeNameDescription
Mirage.SocketLayer.IEndPointendPointthe endpoint to listen on

Connect(IEndPoint)

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

Declaration
void Connect(IEndPoint endPoint)
Parameters
TypeNameDescription
Mirage.SocketLayer.IEndPointendPoint

Close()

Closes the socket, stops receiving messages from other peers

Declaration
void Close()

Poll()

Checks if a packet is available

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

Receive(Byte[], out IEndPoint)

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(byte[] buffer, out IEndPoint endPoint)
Parameters
TypeNameDescription
System.Byte[]bufferbuffer to write recevived packet into
Mirage.SocketLayer.IEndPointendPointwhere packet came from
Returns
TypeDescription
System.Int32length of packet, should not be above buffer length

Send(IEndPoint, Byte[], Int32)

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(IEndPoint endPoint, byte[] packet, int length)
Parameters
TypeNameDescription
Mirage.SocketLayer.IEndPointendPointwhere packet is being sent to
System.Byte[]packetbuffer that contains the packet, starting at index 0
System.Int32lengthlength of the packet