This page has been translated automatically.
UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Content Creation
Materials
Unigine Material Library
Tutorials
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

Unigine::Socket Class

Interface for data handling.

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

Unigine::Socket Class

Members


static Ptr< Socket > create ()

Socket constructor.

static Ptr< Socket > create (const StreamPtr & stream)

Socket constructor.

Arguments

  • const StreamPtr & stream - Stream smart pointer.

virtual int open (int port) const =0

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.

virtual int open (const char * host, int port) const =0

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

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.

virtual void close () const =0

Closes the socket.

virtual int send (int size) const =0

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.

virtual int recv (int size) const =0

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.

virtual int bind () const =0

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.

virtual int listen (int num) const =0

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.

virtual int accept (Ptr< Socket > socket) const =0

Accepts a connection on the socket.

Arguments

  • 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.

virtual int connect () const =0

Initiates a connection on the socket.

Return value

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

virtual int broadcast () const =0

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.

virtual int nonblock () const =0

Makes the socket a non-blocking one.

Return value

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

virtual int nodelay () const =0

Enables Nagle's algorithm.

Return value

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

virtual const char * getHost () const =0

Returns the host name on which the socket is opened.

Return value

Host name.

virtual int getPort () const =0

Returns the port number on which the socket is opened.

Return value

Port number.

virtual int getFD () const =0

Returns the socket file descriptor.

Return value

Socket file descriptor.

Unigine::Socket::anonymous_79 Enumeration

SOCKET_STREAM = 0
SOCKET_DGRAM
Last update: 2017-07-03
Build: ()