StreamPeerTCP.xml 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="StreamPeerTCP" inherits="StreamPeer" version="4.0">
  3. <brief_description>
  4. TCP stream peer.
  5. </brief_description>
  6. <description>
  7. TCP stream peer. This object can be used to connect to TCP servers, or also is returned by a TCP server.
  8. [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.
  9. </description>
  10. <tutorials>
  11. </tutorials>
  12. <methods>
  13. <method name="bind">
  14. <return type="int" enum="Error" />
  15. <argument index="0" name="port" type="int" />
  16. <argument index="1" name="host" type="String" default="&quot;*&quot;" />
  17. <description>
  18. Opens the TCP socket, and binds it to the specified local address.
  19. 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.
  20. </description>
  21. </method>
  22. <method name="connect_to_host">
  23. <return type="int" enum="Error" />
  24. <argument index="0" name="host" type="String" />
  25. <argument index="1" name="port" type="int" />
  26. <description>
  27. Connects to the specified [code]host:port[/code] pair. A hostname will be resolved if valid. Returns [constant OK] on success.
  28. </description>
  29. </method>
  30. <method name="disconnect_from_host">
  31. <return type="void" />
  32. <description>
  33. Disconnects from host.
  34. </description>
  35. </method>
  36. <method name="get_connected_host" qualifiers="const">
  37. <return type="String" />
  38. <description>
  39. Returns the IP of this peer.
  40. </description>
  41. </method>
  42. <method name="get_connected_port" qualifiers="const">
  43. <return type="int" />
  44. <description>
  45. Returns the port of this peer.
  46. </description>
  47. </method>
  48. <method name="get_local_port" qualifiers="const">
  49. <return type="int" />
  50. <description>
  51. Returns the local port to which this peer is bound.
  52. </description>
  53. </method>
  54. <method name="get_status">
  55. <return type="int" enum="StreamPeerTCP.Status" />
  56. <description>
  57. Returns the status of the connection, see [enum Status].
  58. </description>
  59. </method>
  60. <method name="is_connected_to_host" qualifiers="const">
  61. <return type="bool" />
  62. <description>
  63. Returns [code]true[/code] if this peer is currently connected or is connecting to a host, [code]false[/code] otherwise.
  64. </description>
  65. </method>
  66. <method name="set_no_delay">
  67. <return type="void" />
  68. <argument index="0" name="enabled" type="bool" />
  69. <description>
  70. 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].
  71. [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.
  72. </description>
  73. </method>
  74. </methods>
  75. <constants>
  76. <constant name="STATUS_NONE" value="0" enum="Status">
  77. The initial status of the [StreamPeerTCP]. This is also the status after disconnecting.
  78. </constant>
  79. <constant name="STATUS_CONNECTING" value="1" enum="Status">
  80. A status representing a [StreamPeerTCP] that is connecting to a host.
  81. </constant>
  82. <constant name="STATUS_CONNECTED" value="2" enum="Status">
  83. A status representing a [StreamPeerTCP] that is connected to a host.
  84. </constant>
  85. <constant name="STATUS_ERROR" value="3" enum="Status">
  86. A status representing a [StreamPeerTCP] in error state.
  87. </constant>
  88. </constants>
  89. </class>