This page has been translated automatically.
Programming
Fundamentials
Setting Up Development Environment
UnigineScript
High-Level Systems
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Bounds-Related Classes
Containers
Controls-Related Classes
Engine-Related Classes
GUI-Related Classes
Node-Related Classes
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
Rendering-Related Classes
Utility Classes
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

Interface for data handling.

To use this class, include the UnigineSocket.h file.

Socket Class

Members


Socket (int type)

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 type - 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, const char * 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.
  • const char * host - Host, on which the socket will be opened.
  • int port - Port, on which the socket will be opened.

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 number, on which the socket will be opened.

Return value

Returns 1 if the socket is opened successfully; otherwise, 0.

Ptr<Socket> create (const Ptr<Stream> & stream)

Socket constructor.

Arguments

  • const Ptr<Stream> & stream - Stream smart pointer.

Return value

int bind ()

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

Return value

Returns 1 if the address is bound; otherwise, 0.

int close ()

Closes the socket.

Return value

int nonblock ()

Makes the socket a non-blocking one.

Return value

Returns 1 if the has become non-blocking; otherwise, 0.

int listenMulticastGroup ()

Return value

const char * getHost ()

Returns the host name on which the socket is opened.

Return value

Host name.

int open (const char * host, 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

  • const char * host - Host name, on which the socket will be opened.
  • int port - Port number, on which the socket will be opened.

Return value

Returns 1 if the socket is opened successfully; otherwise, 0.

int accept (const Ptr<Socket> & socket)

Accepts a connection on the socket.

Arguments

  • const Ptr<Socket> & socket - Socket that is bound to an address and listens to connections.

Return value

Returns 1 if the connection is accepted; otherwise, 0.

int send (int size)

Resizes an internal sending buffer for a socket.

Arguments

  • int size - Send buffer size in bytes.

Return value

Returns 1 if the buffer is resized successfully; otherwise, 0.

int recv (int size)

Resizes an internal receiving buffer for a socket.

Arguments

  • int size - Receive buffer size in bytes.

Return value

Returns 1 if the buffer is resized successfully; 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

Returns 1 if the socket is set up successfully ; otherwise, 0 is returned.

int getFD ()

Returns the socket file descriptor.

Return value

Socket file descriptor.

int block ()

Return value

int getPort ()

Returns the port number on which the socket is opened.

Return value

Port number.

int connect ()

Initiates a connection on the socket.

Return value

Returns 1 if the connection is initialized; otherwise, 0.

int listen (int num)

Makes the socket listen to connections.

Arguments

  • int num - Maximum number of pending connections.

Return value

Returns 1 if the socket has started listening; otherwise, 0.

int nodelay ()

Enables Nagle's algorithm.

Return value

Returns 1 if the algorithm has been enabled successfully; otherwise, 0.

int SOCKET_STREAM

Description

Socket for TCP packets.

int SOCKET_DGRAM

Description

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