Document websocket module, further document enet
This commit is contained in:
parent
cbb744c4e0
commit
dd546dc5b8
|
@ -1,57 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<class name="WebSocketClient" inherits="WebSocketMultiplayerPeer" category="Core" version="3.1">
|
|
||||||
<brief_description>
|
|
||||||
</brief_description>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
<tutorials>
|
|
||||||
</tutorials>
|
|
||||||
<demos>
|
|
||||||
</demos>
|
|
||||||
<methods>
|
|
||||||
<method name="connect_to_url">
|
|
||||||
<return type="int" enum="Error">
|
|
||||||
</return>
|
|
||||||
<argument index="0" name="url" type="String">
|
|
||||||
</argument>
|
|
||||||
<argument index="1" name="protocols" type="PoolStringArray" default="PoolStringArray( )">
|
|
||||||
</argument>
|
|
||||||
<argument index="2" name="gd_mp_api" type="bool" default="false">
|
|
||||||
</argument>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</method>
|
|
||||||
<method name="disconnect_from_host">
|
|
||||||
<return type="void">
|
|
||||||
</return>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</method>
|
|
||||||
</methods>
|
|
||||||
<members>
|
|
||||||
<member name="verify_ssl" type="bool" setter="set_verify_ssl_enabled" getter="is_verify_ssl_enabled">
|
|
||||||
</member>
|
|
||||||
</members>
|
|
||||||
<signals>
|
|
||||||
<signal name="connection_closed">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</signal>
|
|
||||||
<signal name="connection_error">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</signal>
|
|
||||||
<signal name="connection_established">
|
|
||||||
<argument index="0" name="protocol" type="String">
|
|
||||||
</argument>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</signal>
|
|
||||||
<signal name="data_received">
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</signal>
|
|
||||||
</signals>
|
|
||||||
<constants>
|
|
||||||
</constants>
|
|
||||||
</class>
|
|
|
@ -1,51 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<class name="WebSocketPeer" inherits="PacketPeer" category="Core" version="3.1">
|
|
||||||
<brief_description>
|
|
||||||
</brief_description>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
<tutorials>
|
|
||||||
</tutorials>
|
|
||||||
<demos>
|
|
||||||
</demos>
|
|
||||||
<methods>
|
|
||||||
<method name="close">
|
|
||||||
<return type="void">
|
|
||||||
</return>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</method>
|
|
||||||
<method name="get_write_mode" qualifiers="const">
|
|
||||||
<return type="int" enum="WebSocketPeer.WriteMode">
|
|
||||||
</return>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</method>
|
|
||||||
<method name="is_connected_to_host" qualifiers="const">
|
|
||||||
<return type="bool">
|
|
||||||
</return>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</method>
|
|
||||||
<method name="set_write_mode">
|
|
||||||
<return type="void">
|
|
||||||
</return>
|
|
||||||
<argument index="0" name="mode" type="int" enum="WebSocketPeer.WriteMode">
|
|
||||||
</argument>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</method>
|
|
||||||
<method name="was_string_packet" qualifiers="const">
|
|
||||||
<return type="bool">
|
|
||||||
</return>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</method>
|
|
||||||
</methods>
|
|
||||||
<constants>
|
|
||||||
<constant name="WRITE_MODE_TEXT" value="0" enum="WriteMode">
|
|
||||||
</constant>
|
|
||||||
<constant name="WRITE_MODE_BINARY" value="1" enum="WriteMode">
|
|
||||||
</constant>
|
|
||||||
</constants>
|
|
||||||
</class>
|
|
|
@ -1,69 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<class name="WebSocketServer" inherits="WebSocketMultiplayerPeer" category="Core" version="3.1">
|
|
||||||
<brief_description>
|
|
||||||
</brief_description>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
<tutorials>
|
|
||||||
</tutorials>
|
|
||||||
<demos>
|
|
||||||
</demos>
|
|
||||||
<methods>
|
|
||||||
<method name="has_peer" qualifiers="const">
|
|
||||||
<return type="bool">
|
|
||||||
</return>
|
|
||||||
<argument index="0" name="id" type="int">
|
|
||||||
</argument>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</method>
|
|
||||||
<method name="is_listening" qualifiers="const">
|
|
||||||
<return type="bool">
|
|
||||||
</return>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</method>
|
|
||||||
<method name="listen">
|
|
||||||
<return type="int" enum="Error">
|
|
||||||
</return>
|
|
||||||
<argument index="0" name="port" type="int">
|
|
||||||
</argument>
|
|
||||||
<argument index="1" name="protocols" type="PoolStringArray" default="PoolStringArray( )">
|
|
||||||
</argument>
|
|
||||||
<argument index="2" name="gd_mp_api" type="bool" default="false">
|
|
||||||
</argument>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</method>
|
|
||||||
<method name="stop">
|
|
||||||
<return type="void">
|
|
||||||
</return>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</method>
|
|
||||||
</methods>
|
|
||||||
<signals>
|
|
||||||
<signal name="client_connected">
|
|
||||||
<argument index="0" name="id" type="int">
|
|
||||||
</argument>
|
|
||||||
<argument index="1" name="protocol" type="String">
|
|
||||||
</argument>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</signal>
|
|
||||||
<signal name="client_disconnected">
|
|
||||||
<argument index="0" name="id" type="int">
|
|
||||||
</argument>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</signal>
|
|
||||||
<signal name="data_received">
|
|
||||||
<argument index="0" name="id" type="int">
|
|
||||||
</argument>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
</signal>
|
|
||||||
</signals>
|
|
||||||
<constants>
|
|
||||||
</constants>
|
|
||||||
</class>
|
|
|
@ -16,6 +16,8 @@
|
||||||
<method name="close_connection">
|
<method name="close_connection">
|
||||||
<return type="void">
|
<return type="void">
|
||||||
</return>
|
</return>
|
||||||
|
<argument index="0" name="wait_usec" type="int" default="100">
|
||||||
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
Closes the connection. Ignored if no connection is currently established. If this is a server it tries to notify all clients before forcibly disconnecting them. If this is a client it simply closes the connection to the server.
|
Closes the connection. Ignored if no connection is currently established. If this is a server it tries to notify all clients before forcibly disconnecting them. If this is a client it simply closes the connection to the server.
|
||||||
</description>
|
</description>
|
||||||
|
@ -23,7 +25,7 @@
|
||||||
<method name="create_client">
|
<method name="create_client">
|
||||||
<return type="int" enum="Error">
|
<return type="int" enum="Error">
|
||||||
</return>
|
</return>
|
||||||
<argument index="0" name="ip" type="String">
|
<argument index="0" name="address" type="String">
|
||||||
</argument>
|
</argument>
|
||||||
<argument index="1" name="port" type="int">
|
<argument index="1" name="port" type="int">
|
||||||
</argument>
|
</argument>
|
||||||
|
@ -31,8 +33,10 @@
|
||||||
</argument>
|
</argument>
|
||||||
<argument index="3" name="out_bandwidth" type="int" default="0">
|
<argument index="3" name="out_bandwidth" type="int" default="0">
|
||||||
</argument>
|
</argument>
|
||||||
|
<argument index="4" name="client_port" type="int" default="0">
|
||||||
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
Create client that connects to a server at address [code]ip[/code] using specified [code]port[/code]. The given IP needs to be in IPv4 or IPv6 address format, for example: [code]192.168.1.1[/code]. The [code]port[/code] is the port the server is listening on. The [code]in_bandwidth[/code] and [code]out_bandwidth[/code] parameters can be used to limit the incoming and outgoing bandwidth to the given number of bytes per second. The default of 0 means unlimited bandwidth. Note that ENet will strategically drop packets on specific sides of a connection between peers to ensure the peer's bandwidth is not overwhelmed. The bandwidth parameters also determine the window size of a connection which limits the amount of reliable packets that may be in transit at any given time. Returns [code]OK[/code] if a client was created, [code]ERR_ALREADY_IN_USE[/code] if this NetworkedMultiplayerEnet instance already has an open connection (in which case you need to call [method close_connection] first) or [code]ERR_CANT_CREATE[/code] if the client could not be created.
|
Create client that connects to a server at [code]address[/code] using specified [code]port[/code]. The given address needs to be either a fully qualified domain nome (e.g. [code]www.example.com[/code]) or an IP address in IPv4 or IPv6 format (e.g. [code]192.168.1.1[/code]). The [code]port[/code] is the port the server is listening on. The [code]in_bandwidth[/code] and [code]out_bandwidth[/code] parameters can be used to limit the incoming and outgoing bandwidth to the given number of bytes per second. The default of 0 means unlimited bandwidth. Note that ENet will strategically drop packets on specific sides of a connection between peers to ensure the peer's bandwidth is not overwhelmed. The bandwidth parameters also determine the window size of a connection which limits the amount of reliable packets that may be in transit at any given time. Returns [code]OK[/code] if a client was created, [code]ERR_ALREADY_IN_USE[/code] if this NetworkedMultiplayerEnet instance already has an open connection (in which case you need to call [method close_connection] first) or [code]ERR_CANT_CREATE[/code] if the client could not be created. If [code]client_port[/code] is specified, the client will also listen to the given port, this is useful in some NAT traveral technique.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="create_server">
|
<method name="create_server">
|
||||||
|
@ -50,6 +54,35 @@
|
||||||
Create server that listens to connections via [code]port[/code]. The port needs to be an available, unused port between 0 and 65535. Note that ports below 1024 are privileged and may require elevated permissions depending on the platform. To change the interface the server listens on, use [method set_bind_ip]. The default IP is the wildcard [code]*[/code], which listens on all available interfaces. [code]max_clients[/code] is the maximum number of clients that are allowed at once, any number up to 4096 may be used, although the achievable number of simultaneous clients may be far lower and depends on the application. For additional details on the bandwidth parameters, see [method create_client]. Returns [code]OK[/code] if a server was created, [code]ERR_ALREADY_IN_USE[/code] if this NetworkedMultiplayerEnet instance already has an open connection (in which case you need to call [method close_connection] first) or [code]ERR_CANT_CREATE[/code] if the server could not be created.
|
Create server that listens to connections via [code]port[/code]. The port needs to be an available, unused port between 0 and 65535. Note that ports below 1024 are privileged and may require elevated permissions depending on the platform. To change the interface the server listens on, use [method set_bind_ip]. The default IP is the wildcard [code]*[/code], which listens on all available interfaces. [code]max_clients[/code] is the maximum number of clients that are allowed at once, any number up to 4096 may be used, although the achievable number of simultaneous clients may be far lower and depends on the application. For additional details on the bandwidth parameters, see [method create_client]. Returns [code]OK[/code] if a server was created, [code]ERR_ALREADY_IN_USE[/code] if this NetworkedMultiplayerEnet instance already has an open connection (in which case you need to call [method close_connection] first) or [code]ERR_CANT_CREATE[/code] if the server could not be created.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="disconnect_peer">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="id" type="int">
|
||||||
|
</argument>
|
||||||
|
<argument index="1" name="now" type="bool" default="false">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Disconnect the given peer. If "now" is set to true, the connection will be closed immediately without flushing queued messages.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="get_peer_address" qualifiers="const">
|
||||||
|
<return type="String">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="id" type="int">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Returns the IP address of the given peer.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="get_peer_port" qualifiers="const">
|
||||||
|
<return type="int">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="id" type="int">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Returns the remote port of the given peer.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="set_bind_ip">
|
<method name="set_bind_ip">
|
||||||
<return type="void">
|
<return type="void">
|
||||||
</return>
|
</return>
|
||||||
|
|
|
@ -768,8 +768,8 @@ void NetworkedMultiplayerENet::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("set_compression_mode", "mode"), &NetworkedMultiplayerENet::set_compression_mode);
|
ClassDB::bind_method(D_METHOD("set_compression_mode", "mode"), &NetworkedMultiplayerENet::set_compression_mode);
|
||||||
ClassDB::bind_method(D_METHOD("get_compression_mode"), &NetworkedMultiplayerENet::get_compression_mode);
|
ClassDB::bind_method(D_METHOD("get_compression_mode"), &NetworkedMultiplayerENet::get_compression_mode);
|
||||||
ClassDB::bind_method(D_METHOD("set_bind_ip", "ip"), &NetworkedMultiplayerENet::set_bind_ip);
|
ClassDB::bind_method(D_METHOD("set_bind_ip", "ip"), &NetworkedMultiplayerENet::set_bind_ip);
|
||||||
ClassDB::bind_method(D_METHOD("get_peer_address"), &NetworkedMultiplayerENet::get_peer_address);
|
ClassDB::bind_method(D_METHOD("get_peer_address", "id"), &NetworkedMultiplayerENet::get_peer_address);
|
||||||
ClassDB::bind_method(D_METHOD("get_peer_port"), &NetworkedMultiplayerENet::get_peer_port);
|
ClassDB::bind_method(D_METHOD("get_peer_port", "id"), &NetworkedMultiplayerENet::get_peer_port);
|
||||||
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "compression_mode", PROPERTY_HINT_ENUM, "None,Range Coder,FastLZ,ZLib,ZStd"), "set_compression_mode", "get_compression_mode");
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "compression_mode", PROPERTY_HINT_ENUM, "None,Range Coder,FastLZ,ZLib,ZStd"), "set_compression_mode", "get_compression_mode");
|
||||||
|
|
||||||
|
|
|
@ -5,3 +5,14 @@ def can_build(platform):
|
||||||
|
|
||||||
def configure(env):
|
def configure(env):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_doc_classes():
|
||||||
|
return [
|
||||||
|
"WebSocketClient",
|
||||||
|
"WebSocketMultiplayerPeer",
|
||||||
|
"WebSocketPeer",
|
||||||
|
"WebSocketServer"
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_doc_path():
|
||||||
|
return "doc_classes"
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<class name="WebSocketClient" inherits="WebSocketMultiplayerPeer" category="Core" version="3.1">
|
||||||
|
<brief_description>
|
||||||
|
A WebSocket client implementation
|
||||||
|
</brief_description>
|
||||||
|
<description>
|
||||||
|
This class implements a WebSocket client compatible with any RFC 6455 complaint WebSocket server.
|
||||||
|
This client can be optionally used as a network peer for the [MultiplayerAPI].
|
||||||
|
After starting the client ([method connect_to_url]), you will need to [method NetworkedMultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]).
|
||||||
|
You will received appropriate signals when connecting, disconnecting, or when new data is available.
|
||||||
|
</description>
|
||||||
|
<tutorials>
|
||||||
|
</tutorials>
|
||||||
|
<demos>
|
||||||
|
</demos>
|
||||||
|
<methods>
|
||||||
|
<method name="connect_to_url">
|
||||||
|
<return type="int" enum="Error">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="url" type="String">
|
||||||
|
</argument>
|
||||||
|
<argument index="1" name="protocols" type="PoolStringArray" default="PoolStringArray( )">
|
||||||
|
</argument>
|
||||||
|
<argument index="2" name="gd_mp_api" type="bool" default="false">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Connect to the given URL requesting one of the given [code]protocols[/code] as sub-protocol.
|
||||||
|
If [code]true[/code] is passed as [code]gd_mp_api[/code], the client will behave like a network peer for the [MultiplayerAPI]. Note: connnections to non Godot servers will not work, and [signal data_received] will not be emitted when this option is true.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="disconnect_from_host">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Disconnect from the server if currently connected.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
</methods>
|
||||||
|
<members>
|
||||||
|
<member name="verify_ssl" type="bool" setter="set_verify_ssl_enabled" getter="is_verify_ssl_enabled">
|
||||||
|
Enable or disable SSL certificate verification. Note: You must specify the certificates to be used in the project settings for it to work when exported.
|
||||||
|
</member>
|
||||||
|
</members>
|
||||||
|
<signals>
|
||||||
|
<signal name="connection_closed">
|
||||||
|
<description>
|
||||||
|
Emitted when the connection to the server is closed.
|
||||||
|
</description>
|
||||||
|
</signal>
|
||||||
|
<signal name="connection_error">
|
||||||
|
<description>
|
||||||
|
Emitted when the connection to the server fails.
|
||||||
|
</description>
|
||||||
|
</signal>
|
||||||
|
<signal name="connection_established">
|
||||||
|
<argument index="0" name="protocol" type="String">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Emitted when a connection with the server is established, [code]protocol[/code] will contain the sub-protocol agreed with the server.
|
||||||
|
</description>
|
||||||
|
</signal>
|
||||||
|
<signal name="data_received">
|
||||||
|
<description>
|
||||||
|
Emitted when a WebSocket message is received. Note: This signal is NOT emitted when used as high level multiplayer peer.
|
||||||
|
</description>
|
||||||
|
</signal>
|
||||||
|
</signals>
|
||||||
|
<constants>
|
||||||
|
</constants>
|
||||||
|
</class>
|
|
@ -1,8 +1,10 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<class name="WebSocketMultiplayerPeer" inherits="NetworkedMultiplayerPeer" category="Core" version="3.1">
|
<class name="WebSocketMultiplayerPeer" inherits="NetworkedMultiplayerPeer" category="Core" version="3.1">
|
||||||
<brief_description>
|
<brief_description>
|
||||||
|
Base class for WebSocket server and client.
|
||||||
</brief_description>
|
</brief_description>
|
||||||
<description>
|
<description>
|
||||||
|
Base class for WebSocket server and client, allowing them to be used as network peer for the [MultiplayerAPI].
|
||||||
</description>
|
</description>
|
||||||
<tutorials>
|
<tutorials>
|
||||||
</tutorials>
|
</tutorials>
|
||||||
|
@ -15,6 +17,7 @@
|
||||||
<argument index="0" name="peer_id" type="int">
|
<argument index="0" name="peer_id" type="int">
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
|
Returns the [WebSocketPeer] associated to the given [code]peer_id[/code].
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
</methods>
|
</methods>
|
||||||
|
@ -23,6 +26,7 @@
|
||||||
<argument index="0" name="peer_source" type="int">
|
<argument index="0" name="peer_source" type="int">
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
|
Emitted when a packet is received from a peer. Note: this signal is only emitted when the client or server is configured to use Godot multiplayer API.
|
||||||
</description>
|
</description>
|
||||||
</signal>
|
</signal>
|
||||||
</signals>
|
</signals>
|
|
@ -0,0 +1,75 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<class name="WebSocketPeer" inherits="PacketPeer" category="Core" version="3.1">
|
||||||
|
<brief_description>
|
||||||
|
A class representing a specific WebSocket connection.
|
||||||
|
</brief_description>
|
||||||
|
<description>
|
||||||
|
This class represent a specific WebSocket connection, you can do lower level operations with it.
|
||||||
|
You can choose to write to the socket in binary or text mode, and you can recognize the mode used for writing by the other peer.
|
||||||
|
</description>
|
||||||
|
<tutorials>
|
||||||
|
</tutorials>
|
||||||
|
<demos>
|
||||||
|
</demos>
|
||||||
|
<methods>
|
||||||
|
<method name="close">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Close this WebSocket connection, actively disconnecting the peer.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="get_connected_host" qualifiers="const">
|
||||||
|
<return type="String">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Returns the IP Address of the connected peer. (Not available in HTML5 export)
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="get_connected_port" qualifiers="const">
|
||||||
|
<return type="int">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Returns the remote port of the connected peer. (Not available in HTML5 export)
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="get_write_mode" qualifiers="const">
|
||||||
|
<return type="int" enum="WebSocketPeer.WriteMode">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Get the current selected write mode. See [enum WriteMode].
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="is_connected_to_host" qualifiers="const">
|
||||||
|
<return type="bool">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Returns [code]true[/code] if this peer is currently connected.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="set_write_mode">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="mode" type="int" enum="WebSocketPeer.WriteMode">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Sets the socket to use the given [enum WriteMode].
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="was_string_packet" qualifiers="const">
|
||||||
|
<return type="bool">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Returns [code]true[/code] if the last received packet was sent as a text payload. See [enum WriteMode]
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
</methods>
|
||||||
|
<constants>
|
||||||
|
<constant name="WRITE_MODE_TEXT" value="0" enum="WriteMode">
|
||||||
|
Specify that WebSockets messages should be transferred as text payload (only valid UTF-8 is allowed).
|
||||||
|
</constant>
|
||||||
|
<constant name="WRITE_MODE_BINARY" value="1" enum="WriteMode">
|
||||||
|
Specify that WebSockets messages should be transferred as binary payload (any byte combination is allowed).
|
||||||
|
</constant>
|
||||||
|
</constants>
|
||||||
|
</class>
|
|
@ -0,0 +1,109 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<class name="WebSocketServer" inherits="WebSocketMultiplayerPeer" category="Core" version="3.1">
|
||||||
|
<brief_description>
|
||||||
|
A WebSocket server implementation
|
||||||
|
</brief_description>
|
||||||
|
<description>
|
||||||
|
This class implements a WebSocket server that can also support the high level multiplayer API.
|
||||||
|
After starting the server ([method listen]), you will need to [method NetworkedMultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]). When clients connect, disconnect, or send data, you will receive the appropriate signal.
|
||||||
|
Note: This class will not work in HTML5 exports due to browser restrictions.
|
||||||
|
</description>
|
||||||
|
<tutorials>
|
||||||
|
</tutorials>
|
||||||
|
<demos>
|
||||||
|
</demos>
|
||||||
|
<methods>
|
||||||
|
<method name="disconnect_peer">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="id" type="int">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Disconnects the given peer.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="get_peer_address" qualifiers="const">
|
||||||
|
<return type="String">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="id" type="int">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Returns the IP address of the given peer.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="get_peer_port" qualifiers="const">
|
||||||
|
<return type="int">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="id" type="int">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Returns the remote port of the given peer.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="has_peer" qualifiers="const">
|
||||||
|
<return type="bool">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="id" type="int">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Returns [code]true[/code] if a peer with the given ID is connected.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="is_listening" qualifiers="const">
|
||||||
|
<return type="bool">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Returns [code]true[/code] if the server is actively listening on a port.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="listen">
|
||||||
|
<return type="int" enum="Error">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="port" type="int">
|
||||||
|
</argument>
|
||||||
|
<argument index="1" name="protocols" type="PoolStringArray" default="PoolStringArray( )">
|
||||||
|
</argument>
|
||||||
|
<argument index="2" name="gd_mp_api" type="bool" default="false">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Start listening on the given port.
|
||||||
|
You can specify the desired subprotocols via the "protocols" array. If the list empty (default), "binary" will be used.
|
||||||
|
You can use this server as a network peer for [MultiplayerAPI] by passing true as "gd_mp_api". Note: [signal data_received] will not be fired and clients other than Godot will not work in this case.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
<method name="stop">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Stop the server and clear its state.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
|
</methods>
|
||||||
|
<signals>
|
||||||
|
<signal name="client_connected">
|
||||||
|
<argument index="0" name="id" type="int">
|
||||||
|
</argument>
|
||||||
|
<argument index="1" name="protocol" type="String">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Emitted when a new client connects. "protocol" will be the sub-protocol agreed with the client.
|
||||||
|
</description>
|
||||||
|
</signal>
|
||||||
|
<signal name="client_disconnected">
|
||||||
|
<argument index="0" name="id" type="int">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Emitted when a client disconnects.
|
||||||
|
</description>
|
||||||
|
</signal>
|
||||||
|
<signal name="data_received">
|
||||||
|
<argument index="0" name="id" type="int">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Emitted when a new message is received. Note: This signal is NOT emitted when used as high level multiplayer peer.
|
||||||
|
</description>
|
||||||
|
</signal>
|
||||||
|
</signals>
|
||||||
|
<constants>
|
||||||
|
</constants>
|
||||||
|
</class>
|
|
@ -44,9 +44,9 @@ void WebSocketServer::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("listen", "port", "protocols", "gd_mp_api"), &WebSocketServer::listen, DEFVAL(PoolVector<String>()), DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("listen", "port", "protocols", "gd_mp_api"), &WebSocketServer::listen, DEFVAL(PoolVector<String>()), DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("stop"), &WebSocketServer::stop);
|
ClassDB::bind_method(D_METHOD("stop"), &WebSocketServer::stop);
|
||||||
ClassDB::bind_method(D_METHOD("has_peer", "id"), &WebSocketServer::has_peer);
|
ClassDB::bind_method(D_METHOD("has_peer", "id"), &WebSocketServer::has_peer);
|
||||||
ClassDB::bind_method(D_METHOD("get_peer_address"), &WebSocketServer::get_peer_address);
|
ClassDB::bind_method(D_METHOD("get_peer_address", "id"), &WebSocketServer::get_peer_address);
|
||||||
ClassDB::bind_method(D_METHOD("get_peer_port"), &WebSocketServer::get_peer_port);
|
ClassDB::bind_method(D_METHOD("get_peer_port", "id"), &WebSocketServer::get_peer_port);
|
||||||
ClassDB::bind_method(D_METHOD("disconnect_peer"), &WebSocketServer::disconnect_peer);
|
ClassDB::bind_method(D_METHOD("disconnect_peer", "id"), &WebSocketServer::disconnect_peer);
|
||||||
|
|
||||||
ADD_SIGNAL(MethodInfo("client_disconnected", PropertyInfo(Variant::INT, "id")));
|
ADD_SIGNAL(MethodInfo("client_disconnected", PropertyInfo(Variant::INT, "id")));
|
||||||
ADD_SIGNAL(MethodInfo("client_connected", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::STRING, "protocol")));
|
ADD_SIGNAL(MethodInfo("client_connected", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::STRING, "protocol")));
|
||||||
|
|
Loading…
Reference in New Issue