This page has been translated automatically.
UnigineScript
The Language
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
Usage Examples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Migration
Migrating to UNIGINE 2.0
C++ API Migration
Migrating from UNIGINE 2.0 to UNIGINE 2.1
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Socket Class

This class provides basic functionality for network interaction using stream sockets.

Socket Class

This class inherits from Stream

Members


Socket (int port)

Creates a socket and opens it on a given port. When the socket receives data, packets from all network interfaces will be received. When the socket sends data, the default IP address will be used.

Arguments

  • int port - Port, on which the socket will be opened.

Socket (int type, int port)

Creates a socket for TCP or UDP connections and opens it on a given port. When the socket receives data, packets from all network interfaces will be received. When the socket sends data, the default IP address will be used.

Arguments

  • int type - Socket for TCP (SOCKET_STREAM variable) or UDP (SOCKET_DGRAM) connections.
  • int port - Port, on which the socket will be opened.

Socket (int type, string host, int port)

Creates a socket for TCP or UDP connections and opens it on a given host and a given port. The host specifies the address, from and to which data will be sent.

Arguments

  • int type - Socket for TCP (SOCKET_STREAM variable) or UDP (SOCKET_DGRAM) connections.
  • string host - Host, on which the socket will be opened.
  • int port - Port, on which the socket will be opened.

int accept (Socket socket)

Accepts a connection on the socket.

Arguments

  • Socket socket - Socket that is bound to an address and listens to connections.

Return value

1 if a connection is accepted; otherwise, 0.

int bind ()

Binds the socket to an address figured out from the host used for initialization of the socket.

Return value

1 if an address is bound; otherwise, 0.

int block ()

Sets up a blocking socket.

Return value

1 if the socket is opened; otherwise, 0.

int broadcast ()

Sets up a broadcast socket. To create a broadcast socket, you need to create it with a broadcast host address first and then use this function.

Return value

1 if the socket is opened; otherwise, 0.

void close ()

Closes the socket.

int connect ()

Initiates a connection on the socket.

Return value

1 if a connection is initialized; otherwise, 0.

string getHost ()

Returns a host on which the socket is opened.

Return value

Host IP address.

int getPort ()

Returns a port on which the socket is opened.

Return value

Port number.

int listen (int max)

Makes the socket listen to connections.

Arguments

  • int max - Maximum number of pending connections.

Return value

1 if the socket starts listening; otherwise, 0.

int nodelay ()

Unsets flags that limit transmission rate.

Return value

1 if the flags were unset successfully; otherwise, 0.

int nonblock ()

Makes the socket be non-blocking.

Return value

Positive value if the socket became non-blocking, otherwise 0.

int open (int port)

Opens the socket on a given port. When the socket receives data, packets from all network interfaces will be received. When the socket sends data, the default IP address will be used.

Arguments

  • int port - Port, on which the socket will be opened.

Return value

1 if the socket is opened; otherwise, 0.

int open (string host, int port)

Opens the socket on a given port. The host specifies the address, from and to which data will be sent.

Arguments

  • string host - Host, on which the socket will be opened.
  • int port - Port, on which the socket will be opened.

Return value

1 if the socket is opened; otherwise, 0.

int recv (int size)

Resizes an internal receiving buffer for a socket.

Arguments

  • int size - New buffer size in bytes.

Return value

1 if the operation was a success; otherwise, 0.

int send (int size)

Resizes an internal sending buffer for a socket.

Arguments

  • int size - New buffer size in bytes.

Return value

1 if the operation was a success; otherwise, 0.

int SOCKET_DGRAM

Description

Socket for UDP packets.

int SOCKET_STREAM

Description

Socket for TCP packets.
Last update: 2017-07-03
Build: ()