Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
TCPServer
繼承: SocketServer < RefCounted < Object
TCP 伺服器。
說明
A TCP server. Listens to connections on a port and returns a StreamPeerTCP when it gets an incoming connection.
Note: When exporting to Android, make sure to enable the INTERNET permission in the Android export preset before exporting the project or using remote deploy. Otherwise, network communication of any kind will be blocked by Android.
方法
get_local_port() const |
|
方法說明
返回該伺服器正在監聽的本地埠。
Error listen(port: int, bind_address: String = "*") 🔗
在 port 上監聽與 bind_address 綁定的位址。
如果 bind_address 被設定為 "*"(預設),該伺服器將監聽所有可用位址(包括 IPv4 和 IPv6)。
如果 bind_address 被設定為 "0.0.0.0"(用於 IPv4)或 "::"(用於 IPv6),該伺服器將監聽所有符合該 IP 型別的可用位址。
如果 bind_address 被設定為任何有效的位址(如 "192.168.1.101"、"::1" 等),該伺服器將只在具有該位址的介面上監聽(如果不存在具有該位址的介面則失敗)。
StreamPeerTCP take_connection() 🔗
如果連接可用,則返回帶有該連接的 StreamPeerTCP。