summaryrefslogtreecommitdiff
path: root/modules/websocket
diff options
context:
space:
mode:
Diffstat (limited to 'modules/websocket')
-rw-r--r--modules/websocket/doc_classes/WebSocketClient.xml18
-rw-r--r--modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml21
-rw-r--r--modules/websocket/doc_classes/WebSocketPeer.xml18
-rw-r--r--modules/websocket/doc_classes/WebSocketServer.xml19
-rw-r--r--modules/websocket/emws_client.cpp6
-rw-r--r--modules/websocket/emws_client.h1
-rw-r--r--modules/websocket/emws_server.cpp4
-rw-r--r--modules/websocket/emws_server.h1
-rw-r--r--modules/websocket/lws_client.cpp11
-rw-r--r--modules/websocket/lws_client.h1
-rw-r--r--modules/websocket/lws_server.cpp11
-rw-r--r--modules/websocket/lws_server.h1
-rw-r--r--modules/websocket/websocket_client.h2
-rw-r--r--modules/websocket/websocket_multiplayer_peer.cpp1
-rw-r--r--modules/websocket/websocket_multiplayer_peer.h3
-rw-r--r--modules/websocket/websocket_server.h2
16 files changed, 93 insertions, 27 deletions
diff --git a/modules/websocket/doc_classes/WebSocketClient.xml b/modules/websocket/doc_classes/WebSocketClient.xml
index 26122dfad4..0d425ad1dd 100644
--- a/modules/websocket/doc_classes/WebSocketClient.xml
+++ b/modules/websocket/doc_classes/WebSocketClient.xml
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="WebSocketClient" inherits="WebSocketMultiplayerPeer" category="Core" version="3.2">
<brief_description>
- A WebSocket client implementation
+ A WebSocket client implementation.
</brief_description>
<description>
- This class implements a WebSocket client compatible with any RFC 6455 complaint WebSocket server.
+ This class implements a WebSocket client compatible with any RFC 6455-compliant 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.
+ You will receive appropriate signals when connecting, disconnecting, or when new data is available.
</description>
<tutorials>
</tutorials>
@@ -22,8 +22,8 @@
<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], connections to non Godot servers will not work, and [signal data_received] will not be emitted.
+ Connects 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], connections to non-Godot servers will not work, and [signal data_received] will not be emitted.
If [code]false[/code] is passed instead (default), you must call [PacketPeer] functions ([code]put_packet[/code], [code]get_packet[/code], etc.) on the [WebSocketPeer] returned via [code]get_peer(1)[/code] and not on this object directly (e.g. [code]get_peer(1).put_packet(data)[/code]).
</description>
</method>
@@ -35,13 +35,14 @@
<argument index="1" name="reason" type="String" default="&quot;&quot;">
</argument>
<description>
- Disconnect this client from the connected host. See [method WebSocketPeer.close] for more info.
+ Disconnects this client from the connected host. See [method WebSocketPeer.close] for more information.
</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.
+ If [code]true[/code], SSL certificate verification is enabled.
+ [b]Note:[/b] You must specify the certificates to be used in the Project Settings for it to work when exported.
</member>
</members>
<signals>
@@ -66,7 +67,8 @@
</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.
+ Emitted when a WebSocket message is received.
+ [b]Note:[/b] This signal is [i]not[/i] emitted when used as high-level multiplayer peer.
</description>
</signal>
<signal name="server_close_request">
diff --git a/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml b/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml
index 8548d21323..b80a28e648 100644
--- a/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml
+++ b/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml
@@ -18,13 +18,32 @@
Returns the [WebSocketPeer] associated to the given [code]peer_id[/code].
</description>
</method>
+ <method name="set_buffers">
+ <return type="int" enum="Error">
+ </return>
+ <argument index="0" name="input_buffer_size_kb" type="int">
+ </argument>
+ <argument index="1" name="input_max_packets" type="int">
+ </argument>
+ <argument index="2" name="output_buffer_size_kb" type="int">
+ </argument>
+ <argument index="3" name="output_max_packets" type="int">
+ </argument>
+ <description>
+ Configures the buffer sizes for this WebSocket peer. Default values can be specified in the Project Settings under [code]network/limits[/code]. For server, values are meant per connected peer.
+ The first two parameters define the size and queued packets limits of the input buffer, the last two of the output buffer.
+ Buffer sizes are expressed in KiB, so [code]4 = 2^12 = 4096 bytes[/code]. All parameters will be rounded up to the nearest power of two.
+ [b]Note:[/b] HTML5 exports only use the input buffer since the output one is managed by browsers.
+ </description>
+ </method>
</methods>
<signals>
<signal name="peer_packet">
<argument index="0" name="peer_source" type="int">
</argument>
<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.
+ Emitted when a packet is received from a peer.
+ [b]Note:[/b] This signal is only emitted when the client or server is configured to use Godot multiplayer API.
</description>
</signal>
</signals>
diff --git a/modules/websocket/doc_classes/WebSocketPeer.xml b/modules/websocket/doc_classes/WebSocketPeer.xml
index 8a6868d311..dd95f7432e 100644
--- a/modules/websocket/doc_classes/WebSocketPeer.xml
+++ b/modules/websocket/doc_classes/WebSocketPeer.xml
@@ -18,30 +18,32 @@
<argument index="1" name="reason" type="String" default="&quot;&quot;">
</argument>
<description>
- Close this WebSocket connection. [code]code[/code] is the status code for the closure (see RFC6455 section 7.4 for a list of valid status codes). [code]reason[/code] is the human readable reason for closing the connection (can be any UTF8 string, must be less than 123 bytes).
- Note: To achieve a clean close, you will need to keep polling until either [signal WebSocketClient.connection_closed] or [signal WebSocketServer.client_disconnected] is received.
- Note: HTML5 export might not support all status codes. Please refer to browsers-specific documentation for more details.
+ Closes this WebSocket connection. [code]code[/code] is the status code for the closure (see RFC 6455 section 7.4 for a list of valid status codes). [code]reason[/code] is the human readable reason for closing the connection (can be any UTF-8 string that's smaller than 123 bytes).
+ [b]Note:[/b] To achieve a clean close, you will need to keep polling until either [signal WebSocketClient.connection_closed] or [signal WebSocketServer.client_disconnected] is received.
+ [b]Note:[/b] The HTML5 export might not support all status codes. Please refer to browser-specific documentation for more details.
</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)
+ Returns the IP address of the connected peer.
+ [b]Note:[/b] Not available in the 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)
+ Returns the remote port of the connected peer.
+ [b]Note:[/b] Not available in the 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].
+ Gets the current selected write mode. See [enum WriteMode].
</description>
</method>
<method name="is_connected_to_host" qualifiers="const">
@@ -70,10 +72,10 @@
</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).
+ Specifies 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).
+ Specifies that WebSockets messages should be transferred as binary payload (any byte combination is allowed).
</constant>
</constants>
</class>
diff --git a/modules/websocket/doc_classes/WebSocketServer.xml b/modules/websocket/doc_classes/WebSocketServer.xml
index 51945d410a..1af5e403e6 100644
--- a/modules/websocket/doc_classes/WebSocketServer.xml
+++ b/modules/websocket/doc_classes/WebSocketServer.xml
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="WebSocketServer" inherits="WebSocketMultiplayerPeer" category="Core" version="3.2">
<brief_description>
- A WebSocket server implementation
+ A WebSocket server implementation.
</brief_description>
<description>
- This class implements a WebSocket server that can also support the high level multiplayer API.
+ 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.
+ [b]Note:[/b] This class will not work in HTML5 exports due to browser restrictions.
</description>
<tutorials>
</tutorials>
@@ -21,7 +21,7 @@
<argument index="2" name="reason" type="String" default="&quot;&quot;">
</argument>
<description>
- Disconnects the peer identified by [code]id[/code] from the server. See [method WebSocketPeer.close] for more info.
+ Disconnects the peer identified by [code]id[/code] from the server. See [method WebSocketPeer.close] for more information.
</description>
</method>
<method name="get_peer_address" qualifiers="const">
@@ -68,17 +68,17 @@
<argument index="2" name="gd_mp_api" type="bool" default="false">
</argument>
<description>
- Start listening on the given port.
+ Starts listening on the given port.
You can specify the desired subprotocols via the "protocols" array. If the list empty (default), "binary" will be used.
- If [code]true[/code] is passed as [code]gd_mp_api[/code], the server will behave like a network peer for the [MultiplayerAPI], connections from non Godot clients will not work, and [signal data_received] will not be emitted.
- If [code]false[/code] is passed instead (default), you must call [PacketPeer] functions ([code]put_packet[/code], [code]get_packet[/code], etc.), on the [WebSocketPeer] returned via [code]get_peer(ID)[/code] to communicate with the peer with given [code]ID[/code] (e.g. [code]get_peer(ID).get_available_packet_count[/code]).
+ If [code]true[/code] is passed as [code]gd_mp_api[/code], the server will behave like a network peer for the [MultiplayerAPI], connections from non-Godot clients will not work, and [signal data_received] will not be emitted.
+ If [code]false[/code] is passed instead (default), you must call [PacketPeer] functions ([code]put_packet[/code], [code]get_packet[/code], etc.), on the [WebSocketPeer] returned via [code]get_peer(id)[/code] to communicate with the peer with given [code]id[/code] (e.g. [code]get_peer(id).get_available_packet_count[/code]).
</description>
</method>
<method name="stop">
<return type="void">
</return>
<description>
- Stop the server and clear its state.
+ Stops the server and clear its state.
</description>
</method>
</methods>
@@ -116,7 +116,8 @@
<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.
+ Emitted when a new message is received.
+ [b]Note:[/b] This signal is [i]not[/i] emitted when used as high-level multiplayer peer.
</description>
</signal>
</signals>
diff --git a/modules/websocket/emws_client.cpp b/modules/websocket/emws_client.cpp
index aafae8f1c2..409cc9f699 100644
--- a/modules/websocket/emws_client.cpp
+++ b/modules/websocket/emws_client.cpp
@@ -205,6 +205,12 @@ int EMWSClient::get_max_packet_size() const {
return (1 << _in_buf_size) - PROTO_SIZE;
}
+Error EMWSClient::set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets) {
+ _in_buf_size = nearest_shift(p_in_buffer - 1) + 10;
+ _in_pkt_size = nearest_shift(p_in_packets - 1);
+ return OK;
+}
+
EMWSClient::EMWSClient() {
_in_buf_size = nearest_shift((int)GLOBAL_GET(WSC_IN_BUF) - 1) + 10;
_in_pkt_size = nearest_shift((int)GLOBAL_GET(WSC_IN_PKT) - 1);
diff --git a/modules/websocket/emws_client.h b/modules/websocket/emws_client.h
index 9bc29c1913..1811d05eea 100644
--- a/modules/websocket/emws_client.h
+++ b/modules/websocket/emws_client.h
@@ -49,6 +49,7 @@ private:
public:
bool _is_connecting;
+ Error set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets);
Error connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, PoolVector<String> p_protocol = PoolVector<String>());
Ref<WebSocketPeer> get_peer(int p_peer_id) const;
void disconnect_from_host(int p_code = 1000, String p_reason = "");
diff --git a/modules/websocket/emws_server.cpp b/modules/websocket/emws_server.cpp
index 0eef1c4ba9..c4bb459ad0 100644
--- a/modules/websocket/emws_server.cpp
+++ b/modules/websocket/emws_server.cpp
@@ -79,6 +79,10 @@ int EMWSServer::get_max_packet_size() const {
return 0;
}
+Error EMWSServer::set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets) {
+ return OK;
+}
+
EMWSServer::EMWSServer() {
}
diff --git a/modules/websocket/emws_server.h b/modules/websocket/emws_server.h
index bb101cd155..a5e5b4090e 100644
--- a/modules/websocket/emws_server.h
+++ b/modules/websocket/emws_server.h
@@ -42,6 +42,7 @@ class EMWSServer : public WebSocketServer {
GDCIIMPL(EMWSServer, WebSocketServer);
public:
+ Error set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets);
Error listen(int p_port, PoolVector<String> p_protocols = PoolVector<String>(), bool gd_mp_api = false);
void stop();
bool is_listening() const;
diff --git a/modules/websocket/lws_client.cpp b/modules/websocket/lws_client.cpp
index 08df76293b..f139a4ef66 100644
--- a/modules/websocket/lws_client.cpp
+++ b/modules/websocket/lws_client.cpp
@@ -215,6 +215,17 @@ uint16_t LWSClient::get_connected_port() const {
return 1025;
};
+Error LWSClient::set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets) {
+ ERR_EXPLAIN("Buffers sizes can only be set before listening or connecting");
+ ERR_FAIL_COND_V(context != NULL, FAILED);
+
+ _in_buf_size = nearest_shift(p_in_buffer - 1) + 10;
+ _in_pkt_size = nearest_shift(p_in_packets - 1);
+ _out_buf_size = nearest_shift(p_out_buffer - 1) + 10;
+ _out_pkt_size = nearest_shift(p_out_packets - 1);
+ return OK;
+}
+
LWSClient::LWSClient() {
_in_buf_size = nearest_shift((int)GLOBAL_GET(WSC_IN_BUF) - 1) + 10;
_in_pkt_size = nearest_shift((int)GLOBAL_GET(WSC_IN_PKT) - 1);
diff --git a/modules/websocket/lws_client.h b/modules/websocket/lws_client.h
index b3a1237550..df4aabec7f 100644
--- a/modules/websocket/lws_client.h
+++ b/modules/websocket/lws_client.h
@@ -51,6 +51,7 @@ private:
int _out_pkt_size;
public:
+ Error set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets);
Error connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, PoolVector<String> p_protocol = PoolVector<String>());
int get_max_packet_size() const;
Ref<WebSocketPeer> get_peer(int p_peer_id) const;
diff --git a/modules/websocket/lws_server.cpp b/modules/websocket/lws_server.cpp
index 61ccdca74a..482c02dc60 100644
--- a/modules/websocket/lws_server.cpp
+++ b/modules/websocket/lws_server.cpp
@@ -197,6 +197,17 @@ void LWSServer::disconnect_peer(int p_peer_id, int p_code, String p_reason) {
get_peer(p_peer_id)->close(p_code, p_reason);
}
+Error LWSServer::set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets) {
+ ERR_EXPLAIN("Buffers sizes can only be set before listening or connecting");
+ ERR_FAIL_COND_V(context != NULL, FAILED);
+
+ _in_buf_size = nearest_shift(p_in_buffer - 1) + 10;
+ _in_pkt_size = nearest_shift(p_in_packets - 1);
+ _out_buf_size = nearest_shift(p_out_buffer - 1) + 10;
+ _out_pkt_size = nearest_shift(p_out_packets - 1);
+ return OK;
+}
+
LWSServer::LWSServer() {
_in_buf_size = nearest_shift((int)GLOBAL_GET(WSS_IN_BUF) - 1) + 10;
_in_pkt_size = nearest_shift((int)GLOBAL_GET(WSS_IN_PKT) - 1);
diff --git a/modules/websocket/lws_server.h b/modules/websocket/lws_server.h
index 5096ee0f88..b331852d26 100644
--- a/modules/websocket/lws_server.h
+++ b/modules/websocket/lws_server.h
@@ -52,6 +52,7 @@ private:
int _out_pkt_size;
public:
+ Error set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets);
Error listen(int p_port, PoolVector<String> p_protocols = PoolVector<String>(), bool gd_mp_api = false);
void stop();
bool is_listening() const;
diff --git a/modules/websocket/websocket_client.h b/modules/websocket/websocket_client.h
index c464d97c7f..7ddb9468a5 100644
--- a/modules/websocket/websocket_client.h
+++ b/modules/websocket/websocket_client.h
@@ -67,6 +67,8 @@ public:
void _on_disconnect(bool p_was_clean);
void _on_error();
+ virtual Error set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets) = 0;
+
WebSocketClient();
~WebSocketClient();
};
diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp
index 6aab8a7e81..23cbf916eb 100644
--- a/modules/websocket/websocket_multiplayer_peer.cpp
+++ b/modules/websocket/websocket_multiplayer_peer.cpp
@@ -87,6 +87,7 @@ void WebSocketMultiplayerPeer::_clear() {
void WebSocketMultiplayerPeer::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_buffers", "input_buffer_size_kb", "input_max_packets", "output_buffer_size_kb", "output_max_packets"), &WebSocketMultiplayerPeer::set_buffers);
ClassDB::bind_method(D_METHOD("get_peer", "peer_id"), &WebSocketMultiplayerPeer::get_peer);
ADD_SIGNAL(MethodInfo("peer_packet", PropertyInfo(Variant::INT, "peer_source")));
diff --git a/modules/websocket/websocket_multiplayer_peer.h b/modules/websocket/websocket_multiplayer_peer.h
index b050449ee0..7fd97a6595 100644
--- a/modules/websocket/websocket_multiplayer_peer.h
+++ b/modules/websocket/websocket_multiplayer_peer.h
@@ -82,7 +82,7 @@ public:
/* NetworkedMultiplayerPeer */
void set_transfer_mode(TransferMode p_mode);
TransferMode get_transfer_mode() const;
- void set_target_peer(int p_peer_id);
+ void set_target_peer(int p_target_peer);
int get_packet_peer() const;
int get_unique_id() const;
virtual bool is_server() const = 0;
@@ -97,6 +97,7 @@ public:
virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size);
/* WebSocketPeer */
+ virtual Error set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets) = 0;
virtual Ref<WebSocketPeer> get_peer(int p_peer_id) const = 0;
void _process_multiplayer(Ref<WebSocketPeer> p_peer, uint32_t p_peer_id);
diff --git a/modules/websocket/websocket_server.h b/modules/websocket/websocket_server.h
index 7a94c4047b..83c0c10419 100644
--- a/modules/websocket/websocket_server.h
+++ b/modules/websocket/websocket_server.h
@@ -62,6 +62,8 @@ public:
void _on_disconnect(int32_t p_peer_id, bool p_was_clean);
void _on_close_request(int32_t p_peer_id, int p_code, String p_reason);
+ virtual Error set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets) = 0;
+
WebSocketServer();
~WebSocketServer();
};