Class Network
Low-level networking implementation interface with Berkeley sockets.
Inheritance
Namespace: FlaxEngine
Assembly: FlaxEngine.CSharp.dll
Syntax
[Unmanaged]
public static class Network : Object
Methods
Accept(ref NetworkSocket, ref NetworkSocket, out NetworkEndPoint)
Accepts a pending connection.
Declaration
[Unmanaged]
public static bool Accept(ref NetworkSocket serverSocket, ref NetworkSocket newSocket, out NetworkEndPoint newEndPoint)
Parameters
NetworkSocket
serverSocket
The socket. |
NetworkSocket
newSocket
The newly connected socket. |
NetworkEndPoint
newEndPoint
The end point of the new socket. |
Returns
System.Boolean
Returns true on error, otherwise false. |
AddSocketToGroup(ref NetworkSocketGroup, ref NetworkSocket)
Adds a socket to a group.
Declaration
[Unmanaged]
public static int AddSocketToGroup(ref NetworkSocketGroup group, ref NetworkSocket socket)
Parameters
NetworkSocketGroup
group
The group. |
NetworkSocket
socket
The socket. |
Returns
System.Int32
Returns the socket index in group or -1 on error. |
BindSocket(ref NetworkSocket, ref NetworkEndPoint)
Binds a socket to the specified end point.
Declaration
[Unmanaged]
public static bool BindSocket(ref NetworkSocket socket, ref NetworkEndPoint endPoint)
Parameters
NetworkSocket
socket
The socket. |
NetworkEndPoint
endPoint
The end point. |
Returns
System.Boolean
Returns true on error, otherwise false. |
ClearGroup(ref NetworkSocketGroup)
Clears the socket group.
Declaration
[Unmanaged]
public static void ClearGroup(ref NetworkSocketGroup group)
Parameters
NetworkSocketGroup
group
The group. |
ConnectSocket(ref NetworkSocket, ref NetworkEndPoint)
Connects a socket to the specified end point.
Declaration
[Unmanaged]
public static bool ConnectSocket(ref NetworkSocket socket, ref NetworkEndPoint endPoint)
Parameters
NetworkSocket
socket
The socket. |
NetworkEndPoint
endPoint
The end point. |
Returns
System.Boolean
Returns true on error, otherwise false. |
CreateEndPoint(String, String, NetworkIPVersion, out NetworkEndPoint, Boolean)
Creates an end point.
Declaration
[Unmanaged]
public static bool CreateEndPoint(string address, string port, NetworkIPVersion ipv, out NetworkEndPoint endPoint, bool bindable = true)
Parameters
System.String
address
The network address. |
System.String
port
The network port. |
NetworkIPVersion
ipv
The ip version. |
NetworkEndPoint
endPoint
The created end point. |
System.Boolean
bindable
True if the end point will be connected or binded. |
Returns
System.Boolean
Returns true on error, otherwise false. |
CreateSocket(ref NetworkSocket, NetworkProtocol, NetworkIPVersion)
Creates a new native socket.
Declaration
[Unmanaged]
public static bool CreateSocket(ref NetworkSocket socket, NetworkProtocol proto, NetworkIPVersion ipv)
Parameters
NetworkSocket
socket
The socket struct to fill in. |
NetworkProtocol
proto
The protocol. |
NetworkIPVersion
ipv
The ip version. |
Returns
System.Boolean
Returns true on error, otherwise false. |
CreateSocketGroup(UInt32, out NetworkSocketGroup)
Creates a socket group. It allocate memory based on the desired capacity.
Declaration
[Unmanaged]
public static bool CreateSocketGroup(uint capacity, out NetworkSocketGroup group)
Parameters
System.UInt32
capacity
The group capacity (fixed). |
NetworkSocketGroup
group
The group. |
Returns
System.Boolean
Returns true on error, otherwise false. |
DestroySocket(ref NetworkSocket)
Closes native socket.
Declaration
[Unmanaged]
public static bool DestroySocket(ref NetworkSocket socket)
Parameters
NetworkSocket
socket
The socket. |
Returns
System.Boolean
Returns true on error, otherwise false. |
DestroySocketGroup(ref NetworkSocketGroup)
Destroy the socket group, and free the allocated memory.
Declaration
[Unmanaged]
public static bool DestroySocketGroup(ref NetworkSocketGroup group)
Parameters
NetworkSocketGroup
group
The group. |
Returns
System.Boolean
Returns true if the group is already destroyed, otherwise false. |
GetSocketFromGroup(ref NetworkSocketGroup, UInt32, out NetworkSocket)
Gets a socket by index. Some data like socket IPVersion might be undefined.
Declaration
[Unmanaged]
public static bool GetSocketFromGroup(ref NetworkSocketGroup group, uint index, out NetworkSocket socket)
Parameters
NetworkSocketGroup
group
The group. |
System.UInt32
index
The index. |
NetworkSocket
socket
The returned socket. |
Returns
System.Boolean
Returns true on error, otherwise false. |
GetSocketOption(ref NetworkSocket, NetworkSocketOption, out Int32)
Gets the specified socket option.
Declaration
[Unmanaged]
public static bool GetSocketOption(ref NetworkSocket socket, NetworkSocketOption option, out int value)
Parameters
NetworkSocket
socket
The socket. |
NetworkSocketOption
option
The option. |
System.Int32
value
The returned value. |
Returns
System.Boolean
Returns true on error, otherwise false. |
GetSocketState(ref NetworkSocketGroup, UInt32, out NetworkSocketState)
Retrieves socket state.
Declaration
[Unmanaged]
public static bool GetSocketState(ref NetworkSocketGroup group, uint index, out NetworkSocketState state)
Parameters
NetworkSocketGroup
group
The group. |
System.UInt32
index
The socket index in group. |
NetworkSocketState
state
The returned state. |
Returns
System.Boolean
Returns true on error, otherwise false. |
IsReadable(ref NetworkSocket)
Checks for socket readability.
Declaration
[Unmanaged]
public static bool IsReadable(ref NetworkSocket socket)
Parameters
NetworkSocket
socket
The socket. |
Returns
System.Boolean
Returns true when data is available. Otherwise false. |
IsWritable(ref NetworkSocket)
Checks for socket writeability.
Declaration
[Unmanaged]
public static bool IsWritable(ref NetworkSocket socket)
Parameters
NetworkSocket
socket
The socket. |
Returns
System.Boolean
Returns true when data can be written. Otherwise false. |
Listen(ref NetworkSocket, UInt16)
Listens for incoming connection.
Declaration
[Unmanaged]
public static bool Listen(ref NetworkSocket socket, ushort queueSize)
Parameters
NetworkSocket
socket
The socket. |
System.UInt16
queueSize
Pending connection queue size. |
Returns
System.Boolean
Returns true on error, otherwise false. |
Poll(ref NetworkSocketGroup)
Updates sockets states.
Declaration
[Unmanaged]
public static int Poll(ref NetworkSocketGroup group)
Parameters
NetworkSocketGroup
group
The sockets group. |
Returns
System.Int32
Returns -1 on error, The number of elements where states are nonzero, otherwise 0. |
ReadSocket(NetworkSocket, Byte*, UInt32, NetworkEndPoint*)
Reads data on the socket.
Declaration
[Unmanaged]
public static int ReadSocket(NetworkSocket socket, byte *buffer, uint bufferSize, NetworkEndPoint*endPoint = default(NetworkEndPoint*))
Parameters
NetworkSocket
socket
The socket. |
System.Byte*
buffer
The buffer. |
System.UInt32
bufferSize
Size of the buffer. |
NetworkEndPoint*
endPoint
If UDP, the end point from where data is coming. Otherwise nullptr. |
Returns
System.Int32
Returns -1 on error, otherwise bytes read. |
ReadSocket(NetworkSocket, Byte[])
Reads data on the socket.
Declaration
[Unmanaged]
public static int ReadSocket(NetworkSocket socket, byte[] buffer)
Parameters
NetworkSocket
socket
The socket. |
System.Byte[]
buffer
The buffer. |
Returns
System.Int32
Returns -1 on error, otherwise bytes read. |
ReadSocket(NetworkSocket, Byte[], NetworkEndPoint)
Reads data on the socket.
Declaration
[Unmanaged]
public static int ReadSocket(NetworkSocket socket, byte[] buffer, NetworkEndPoint endPoint)
Parameters
NetworkSocket
socket
The socket. |
System.Byte[]
buffer
The buffer. |
NetworkEndPoint
endPoint
If UDP, the end point from where data is coming. Otherwise nullptr. |
Returns
System.Int32
Returns -1 on error, otherwise bytes read. |
RemapEndPointToIPv6(ref NetworkEndPoint)
Remaps an ipv4 end point to an ipv6 one.
Declaration
[Unmanaged]
public static NetworkEndPoint RemapEndPointToIPv6(ref NetworkEndPoint endPoint)
Parameters
NetworkEndPoint
endPoint
The ipv4 end point. |
Returns
NetworkEndPoint
The ipv6 end point. |
RemoveSocketFromGroup(ref NetworkSocketGroup, ref NetworkSocket)
Removes the socket if present.
Declaration
[Unmanaged]
public static bool RemoveSocketFromGroup(ref NetworkSocketGroup group, ref NetworkSocket socket)
Parameters
NetworkSocketGroup
group
The group. |
NetworkSocket
socket
The socket. |
Returns
System.Boolean
Returns true if the socket is not found, otherwise false. |
RemoveSocketFromGroup(ref NetworkSocketGroup, UInt32)
Removes the socket at the specified index.
Declaration
[Unmanaged]
public static void RemoveSocketFromGroup(ref NetworkSocketGroup group, uint index)
Parameters
NetworkSocketGroup
group
The group. |
System.UInt32
index
The index. |
SetSocketOption(ref NetworkSocket, NetworkSocketOption, Int32)
Sets the specified socket option.
Declaration
[Unmanaged]
public static bool SetSocketOption(ref NetworkSocket socket, NetworkSocketOption option, int value)
Parameters
NetworkSocket
socket
The socket. |
NetworkSocketOption
option
The option. |
System.Int32
value
The value. |
Returns
System.Boolean
Returns true on error, otherwise false. |
WriteSocket(NetworkSocket, Byte*, UInt32, NetworkEndPoint*)
Writes data to the socket.
Declaration
[Unmanaged]
public static int WriteSocket(NetworkSocket socket, byte *data, uint length, NetworkEndPoint*endPoint = default(NetworkEndPoint*))
Parameters
NetworkSocket
socket
The socket. |
System.Byte*
data
The data to write. |
System.UInt32
length
The length of data. |
NetworkEndPoint*
endPoint
If protocol is UDP, the destination end point. Otherwise nullptr. |
Returns
System.Int32
Returns -1 on error, otherwise bytes written. |
WriteSocket(NetworkSocket, Byte[])
Writes data to the socket.
Declaration
[Unmanaged]
public static int WriteSocket(NetworkSocket socket, byte[] data)
Parameters
NetworkSocket
socket
The socket. |
System.Byte[]
data
The data to write. |
Returns
System.Int32
Returns -1 on error, otherwise bytes written. |
WriteSocket(NetworkSocket, Byte[], NetworkEndPoint)
Writes data to the socket.
Declaration
[Unmanaged]
public static int WriteSocket(NetworkSocket socket, byte[] data, NetworkEndPoint endPoint)
Parameters
NetworkSocket
socket
The socket. |
System.Byte[]
data
The data to write. |
NetworkEndPoint
endPoint
If protocol is UDP, the destination end point. |
Returns
System.Int32
Returns -1 on error, otherwise bytes written. |