Lua Player Plus Vita
Documentation of lpp-vita
Socket

Module that handles network sockets. More...

Enumerations

enum  NetProtocol { TCP_SOCKET , UDP_SOCKET }
 Network protocols. More...
 

Functions

int Socket::createServerSocket (int port, NetProtocol protocol)
 Create a server socket. More...
 
int Socket::connect (string host, int port, NetProtocol protocol)
 Connect to a server. More...
 
int Socket::send (int sock, string data)
 Send data via socket. More...
 
string Socket::receive (int sock, int size)
 Send data via socket. More...
 
int Socket::accept (int sock)
 Accept new connections for a server socket. More...
 
void Socket::close (int sock)
 Close a socket. More...
 

Detailed Description

Module that handles network sockets.

Enumeration Type Documentation

◆ NetProtocol

Network protocols.

Enumerator
TCP_SOCKET 

TCP protocol.

UDP_SOCKET 

UDP protocol.

Function Documentation

◆ 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:
sock = Socket.connect("192.168.1.8", 5000)
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:
Socket.send(sock, "Hello World!")
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:
data = Socket.receive(sock, 32767)
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:
client = Socket.accept(server)
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
sock- A valid socket id.