This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
专业(SIM)
UnigineEditor
界面概述
资产工作流程
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Landscape Tool
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
创建内容
内容优化
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

Unigine::Socket Class

Header: #include <UnigineStreams.h>
Inherits from: Stream
Read More

Socket Class

Members


static SocketPtr create ( 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.

static SocketPtr create ( 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.

static SocketPtr create ( 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 getFD ( ) const#

Returns the socket file descriptor.

Return value

Socket file descriptor.

const char * getHost ( ) const#

Returns the host name on which the socket is opened.

Return value

Host name.

int getPort ( ) const#

Returns the port number on which the socket is opened.

Return value

Port number.

int accept ( const Ptr<Socket> & socket ) const#

Accepts a connection on the socket.

Arguments

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

Return value

1 if the connection is accepted; otherwise, 0.

int bind ( ) const#

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

Return value

1 if the address is bound; otherwise, 0.

int block ( ) const#

Sets up a blocking socket.

Return value

1 if the socket is opened; otherwise, 0.

int broadcast ( ) const#

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 set up successfully ; otherwise, 0 is returned.

int close ( ) const#

Closes the socket.

int connect ( ) const#

Initiates a connection on the socket.

Return value

1 if the connection is initialized; otherwise, 0.

int listen ( int num ) const#

Makes the socket listen to connections.

Arguments

  • int num - Maximum number of pending connections.

Return value

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

int listenMulticastGroup ( ) const#

Joins the socket to a multicast group. Available for UDP sockets only.
Notice
The socket class doesn't allow creating a multicast server.
Source code (C++)
const int PORT = 8888;
SocketPtr socket = Socket::create(Socket::SOCKET_DGRAM, PORT);
socket->listenMulticastGroup();

Return value

1 if the sockect has been joined successfully; otherwise, 0.

int nodelay ( ) const#

Enables Nagle's algorithm.

Return value

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

int nonblock ( ) const#

Makes the socket a non-blocking one.

Return value

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

int open ( int port ) const#

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

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

int open ( const char * host, int port ) const#

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

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

int recv ( int size ) const#

Resizes an internal receiving buffer for a socket.

Arguments

  • int size - Receive buffer size in bytes.

Return value

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

int send ( int size ) const#

Resizes an internal sending buffer for a socket.

Arguments

  • int size - Send buffer size in bytes.

Return value

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

int isReadyToRead ( int timeout_usec = 0 ) const#

Returns a value indicating whether the socked is ready for reading data, waiting if necessary, to perform synchronous I/O.

Arguments

  • int timeout_usec - The maximum time for to wait for the socket's response, in microseconds. By default, the timeout is 0

Return value

1 if the socket is ready for reading data; otherwise, 0.

int isReadyToWrite ( int timeout_usec = 0 ) const#

Returns a value indicating whether the socked is ready for writing data, waiting if necessary, to perform synchronous I/O.

Arguments

  • int timeout_usec - The maximum time for to wait for the socket's response, in microseconds. By default, the timeout is 0

Return value

1 if the socket is ready for writing data; otherwise, 0.
Last update: 2022-03-10
Build: ()