Module that handles network sockets.
More...
Module that handles network sockets.
◆ NetProtocol
Network protocols.
Enumerator |
---|
TCP_SOCKET | TCP protocol.
|
UDP_SOCKET | UDP protocol.
|
◆ createServerSocket()
int Socket::createServerSocket |
( |
int |
port, |
|
|
NetProtocol |
protocol |
|
) |
| |
Create a server socket.
- Usage example:
Definition: luaSocket.cpp:15
int createServerSocket(int port, NetProtocol protocol)
Create a server socket.
@ TCP_SOCKET
TCP protocol.
Definition: luaSocket.cpp:11
- Parameters
-
port | - Port to use. |
protocol | - Protocol to use (optional). |
- Returns
- The created socket id.
- Note
- If not specified, TCP_SOCKET is used as default.
◆ connect()
int Socket::connect |
( |
string |
host, |
|
|
int |
port, |
|
|
NetProtocol |
protocol |
|
) |
| |
Connect to a server.
- Usage example:
int connect(string host, int port, NetProtocol protocol)
Connect to a server.
- Parameters
-
host | - Host to connect to. |
port | - Port to use. |
protocol | - Protocol to use (optional). |
- Returns
- A valid client socket id.
- Note
- If not specified, TCP_SOCKET is used as default.
◆ send()
int Socket::send |
( |
int |
sock, |
|
|
string |
data |
|
) |
| |
Send data via socket.
- Usage example:
int send(int sock, string data)
Send data via socket.
- Parameters
-
sock | - A valid socket id. |
data | - Data to send. |
- Returns
- Length of the sent data in bytes.
◆ receive()
string Socket::receive |
( |
int |
sock, |
|
|
int |
size |
|
) |
| |
Send data via socket.
- Usage example:
string receive(int sock, int size)
Send data via socket.
- Parameters
-
sock | - A valid socket id. |
size | - Maximum size of the received data. |
- Returns
- The received data.
- Note
- The received data can be smaller than size.
◆ accept()
int Socket::accept |
( |
int |
sock | ) |
|
Accept new connections for a server socket.
- Usage example:
int accept(int sock)
Accept new connections for a server socket.
- Parameters
-
sock | - A valid server socket id. |
- Returns
- A valid client socket id.
◆ close()
void Socket::close |
( |
int |
sock | ) |
|
Close a socket.
- Usage example:
void close(int sock)
Close a socket.
- Parameters
-