2017-09-13 04:42:36 +08:00
<?xml version="1.0" encoding="UTF-8" ?>
2020-02-01 09:03:48 +08:00
<class name= "StreamPeerTCP" inherits= "StreamPeer" version= "4.0" >
2017-09-13 04:42:36 +08:00
<brief_description >
2019-06-22 07:04:47 +08:00
TCP stream peer.
2017-09-13 04:42:36 +08:00
</brief_description>
<description >
2019-06-22 07:04:47 +08:00
TCP stream peer. This object can be used to connect to TCP servers, or also is returned by a TCP server.
2021-08-10 23:47:09 +08:00
[b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android.
2017-09-13 04:42:36 +08:00
</description>
<tutorials >
</tutorials>
<methods >
2021-03-21 18:15:30 +08:00
<method name= "bind" >
2021-07-30 21:28:05 +08:00
<return type= "int" enum= "Error" />
<argument index= "0" name= "port" type= "int" />
<argument index= "1" name= "host" type= "String" default= ""*"" />
2021-03-21 18:15:30 +08:00
<description >
Opens the TCP socket, and binds it to the specified local address.
This method is generally not needed, and only used to force the subsequent call to [method connect_to_host] to use the specified [code]host[/code] and [code]port[/code] as source address. This can be desired in some NAT punchthrough techniques, or when forcing the source network interface.
</description>
</method>
2017-09-13 04:42:36 +08:00
<method name= "connect_to_host" >
2021-07-30 21:28:05 +08:00
<return type= "int" enum= "Error" />
<argument index= "0" name= "host" type= "String" />
<argument index= "1" name= "port" type= "int" />
2017-09-13 04:42:36 +08:00
<description >
2021-03-21 18:15:30 +08:00
Connects to the specified [code]host:port[/code] pair. A hostname will be resolved if valid. Returns [constant OK] on success.
2017-09-13 04:42:36 +08:00
</description>
</method>
<method name= "disconnect_from_host" >
2021-07-30 21:28:05 +08:00
<return type= "void" />
2017-09-13 04:42:36 +08:00
<description >
2019-06-22 07:04:47 +08:00
Disconnects from host.
2017-09-13 04:42:36 +08:00
</description>
</method>
<method name= "get_connected_host" qualifiers= "const" >
2021-07-30 21:28:05 +08:00
<return type= "String" />
2017-09-13 04:42:36 +08:00
<description >
2019-05-24 10:15:43 +08:00
Returns the IP of this peer.
2017-09-13 04:42:36 +08:00
</description>
</method>
<method name= "get_connected_port" qualifiers= "const" >
2021-07-30 21:28:05 +08:00
<return type= "int" />
2017-09-13 04:42:36 +08:00
<description >
2019-05-24 10:15:43 +08:00
Returns the port of this peer.
2017-09-13 04:42:36 +08:00
</description>
</method>
2021-03-21 18:15:30 +08:00
<method name= "get_local_port" qualifiers= "const" >
2021-07-30 21:28:05 +08:00
<return type= "int" />
2021-03-21 18:15:30 +08:00
<description >
Returns the local port to which this peer is bound.
</description>
</method>
2018-09-14 04:54:35 +08:00
<method name= "get_status" >
2021-07-30 21:28:05 +08:00
<return type= "int" enum= "StreamPeerTCP.Status" />
2017-09-13 04:42:36 +08:00
<description >
2019-06-27 17:44:37 +08:00
Returns the status of the connection, see [enum Status].
2017-09-13 04:42:36 +08:00
</description>
</method>
<method name= "is_connected_to_host" qualifiers= "const" >
2021-07-30 21:28:05 +08:00
<return type= "bool" />
2017-09-13 04:42:36 +08:00
<description >
2020-10-07 22:35:33 +08:00
Returns [code]true[/code] if this peer is currently connected or is connecting to a host, [code]false[/code] otherwise.
2017-09-13 04:42:36 +08:00
</description>
</method>
2018-02-19 17:47:16 +08:00
<method name= "set_no_delay" >
2021-07-30 21:28:05 +08:00
<return type= "void" />
<argument index= "0" name= "enabled" type= "bool" />
2018-02-19 17:47:16 +08:00
<description >
2020-11-27 05:25:02 +08:00
If [code]enabled[/code] is [code]true[/code], packets will be sent immediately. If [code]enabled[/code] is [code]false[/code] (the default), packet transfers will be delayed and combined using [url=https://en.wikipedia.org/wiki/Nagle%27s_algorithm]Nagle's algorithm[/url].
[b]Note:[/b] It's recommended to leave this disabled for applications that send large packets or need to transfer a lot of data, as enabling this can decrease the total available bandwidth.
2018-02-19 17:47:16 +08:00
</description>
</method>
2017-09-13 04:42:36 +08:00
</methods>
<constants >
2017-11-25 06:16:30 +08:00
<constant name= "STATUS_NONE" value= "0" enum= "Status" >
2019-06-22 07:04:47 +08:00
The initial status of the [StreamPeerTCP]. This is also the status after disconnecting.
2017-09-13 04:42:36 +08:00
</constant>
2017-11-25 06:16:30 +08:00
<constant name= "STATUS_CONNECTING" value= "1" enum= "Status" >
2019-03-30 06:37:35 +08:00
A status representing a [StreamPeerTCP] that is connecting to a host.
2017-09-13 04:42:36 +08:00
</constant>
2017-11-25 06:16:30 +08:00
<constant name= "STATUS_CONNECTED" value= "2" enum= "Status" >
2019-03-30 06:37:35 +08:00
A status representing a [StreamPeerTCP] that is connected to a host.
2017-09-13 04:42:36 +08:00
</constant>
2017-11-25 06:16:30 +08:00
<constant name= "STATUS_ERROR" value= "3" enum= "Status" >
2019-03-30 06:37:35 +08:00
A status representing a [StreamPeerTCP] in error state.
2017-09-13 04:42:36 +08:00
</constant>
</constants>
</class>