class_tcpserver.rst 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the TCPServer.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_TCPServer:
  6. TCPServer
  7. =========
  8. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  9. A TCP server.
  10. Description
  11. -----------
  12. A TCP server. Listens to connections on a port and returns a :ref:`StreamPeerTCP<class_StreamPeerTCP>` when it gets an incoming connection.
  13. \ **Note:** When exporting to Android, make sure to enable the ``INTERNET`` 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.
  14. Methods
  15. -------
  16. +-------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  17. | :ref:`int<class_int>` | :ref:`get_local_port<class_TCPServer_method_get_local_port>` **(** **)** |const| |
  18. +-------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  19. | :ref:`bool<class_bool>` | :ref:`is_connection_available<class_TCPServer_method_is_connection_available>` **(** **)** |const| |
  20. +-------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`bool<class_bool>` | :ref:`is_listening<class_TCPServer_method_is_listening>` **(** **)** |const| |
  22. +-------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`listen<class_TCPServer_method_listen>` **(** :ref:`int<class_int>` port, :ref:`String<class_String>` bind_address="*" **)** |
  24. +-------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  25. | void | :ref:`stop<class_TCPServer_method_stop>` **(** **)** |
  26. +-------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`StreamPeerTCP<class_StreamPeerTCP>` | :ref:`take_connection<class_TCPServer_method_take_connection>` **(** **)** |
  28. +-------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  29. Method Descriptions
  30. -------------------
  31. .. _class_TCPServer_method_get_local_port:
  32. - :ref:`int<class_int>` **get_local_port** **(** **)** |const|
  33. Returns the local port this server is listening to.
  34. ----
  35. .. _class_TCPServer_method_is_connection_available:
  36. - :ref:`bool<class_bool>` **is_connection_available** **(** **)** |const|
  37. Returns ``true`` if a connection is available for taking.
  38. ----
  39. .. _class_TCPServer_method_is_listening:
  40. - :ref:`bool<class_bool>` **is_listening** **(** **)** |const|
  41. Returns ``true`` if the server is currently listening for connections.
  42. ----
  43. .. _class_TCPServer_method_listen:
  44. - :ref:`Error<enum_@GlobalScope_Error>` **listen** **(** :ref:`int<class_int>` port, :ref:`String<class_String>` bind_address="*" **)**
  45. Listen on the ``port`` binding to ``bind_address``.
  46. If ``bind_address`` is set as ``"*"`` (default), the server will listen on all available addresses (both IPv4 and IPv6).
  47. If ``bind_address`` is set as ``"0.0.0.0"`` (for IPv4) or ``"::"`` (for IPv6), the server will listen on all available addresses matching that IP type.
  48. If ``bind_address`` is set to any valid address (e.g. ``"192.168.1.101"``, ``"::1"``, etc), the server will only listen on the interface with that addresses (or fail if no interface with the given address exists).
  49. ----
  50. .. _class_TCPServer_method_stop:
  51. - void **stop** **(** **)**
  52. Stops listening.
  53. ----
  54. .. _class_TCPServer_method_take_connection:
  55. - :ref:`StreamPeerTCP<class_StreamPeerTCP>` **take_connection** **(** **)**
  56. If a connection is available, returns a StreamPeerTCP with the connection.
  57. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  58. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  59. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  60. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  61. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  62. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`