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
Type | Name | Description |
---|---|---|
Mirage.SocketLayer.IEndPoint | endPoint | the endpoint to listen on |
Connect(IEndPoint)
Sets up Socket ready to send data to endpoint as a client
Declaration
void Connect(IEndPoint endPoint)
Parameters
Type | Name | Description |
---|---|---|
Mirage.SocketLayer.IEndPoint | endPoint |
Close()
Closes the socket, stops receiving messages from other peers
Declaration
void Close()
Poll()
Checks if a packet is available
Declaration
bool Poll()
Returns
Type | Description |
---|---|
System.Boolean | true 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
Type | Name | Description |
---|---|---|
System.Byte[] | buffer | buffer to write recevived packet into |
Mirage.SocketLayer.IEndPoint | endPoint | where packet came from |
Returns
Type | Description |
---|---|
System.Int32 | length 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
Type | Name | Description |
---|---|---|
Mirage.SocketLayer.IEndPoint | endPoint | where packet is being sent to |
System.Byte[] | packet | buffer that contains the packet, starting at index 0 |
System.Int32 | length | length of the packet |