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
| Type | Name | Description |
|---|---|---|
| Mirage.SocketLayer.IBindEndPoint | endPoint | the endPoint to listen on |
Connect(IConnectEndPoint)
Sets up Socket ready to send data to endPoint as a client
Declaration
IConnectionHandle Connect(IConnectEndPoint endPoint)
Parameters
| Type | Name | Description |
|---|---|---|
| Mirage.SocketLayer.IConnectEndPoint | endPoint | the endPoint to connect to |
Returns
| Type | Description |
|---|---|
| Mirage.SocketLayer.IConnectionHandle | returns 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
| Type | Name | Description |
|---|---|---|
| System.Int32 | maxPacketSize | |
| Mirage.SocketLayer.OnData | onData | |
| Mirage.SocketLayer.OnDisconnect | onDisconnect |
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
| Type | Description |
|---|---|
| System.Boolean | true 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
| Type | Name | Description |
|---|---|---|
| Span<System.Byte> | outBuffer | |
| Mirage.SocketLayer.IConnectionHandle | handle |
Returns
| Type | Description |
|---|---|
| System.Int32 | length 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
| Type | Name | Description |
|---|---|---|
| Mirage.SocketLayer.IConnectionHandle | handle | |
| ReadOnlySpan<System.Byte> | packet | buffer that contains the packet, starting at index 0 |