TCPServer

繼承: RefCounted < Object

TCP 伺服器。

說明

TCP 伺服器。監聽埠上的連接,並在獲得傳入連接時返回 StreamPeerTCP

注意:匯出到安卓時,在匯出專案或使用一鍵部署之前,請務必在安卓匯出預設中開啟 INTERNET 許可權。否則 Android 會阻止任何形式的網路通信。

方法

int

get_local_port() const

bool

is_connection_available() const

bool

is_listening() const

Error

listen(port: int, bind_address: String = "*")

void

stop()

StreamPeerTCP

take_connection()


方法說明

int get_local_port() const 🔗

返回該伺服器正在監聽的本地埠。


bool is_connection_available() const 🔗

如果有連接可供獲取,則返回 true


bool is_listening() const 🔗

如果伺服器目前正在偵聽連接,則返回 true


Error listen(port: int, bind_address: String = "*") 🔗

Listen on the port binding to bind_address.

If bind_address is set as "*" (default), the server will listen on all available addresses (both IPv4 and IPv6).

If bind_address is set as "0.0.0.0" (for IPv4) or "::" (for IPv6), the server will listen on all available addresses matching that IP type.

If bind_address is set to any valid address (e.g. "192.168.1.101", "::1", etc.), the server will only listen on the interface with that address (or fail if no interface with the given address exists).


void stop() 🔗

停止監聽。


StreamPeerTCP take_connection() 🔗

如果連接可用,則返回帶有該連接的 StreamPeerTCP。