PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/doc/source/api/Socket/Socket.rst

https://github.com/tinkajts/php-websocket
ReStructuredText | 150 lines | 84 code | 66 blank | 0 comment | 0 complexity | 76e2598f7186373b9b2e03ef5d3e6dda MD5 | raw file
Possible License(s): WTFPL
  1. ----------------------
  2. Wrench\\Socket\\Socket
  3. ----------------------
  4. .. php:namespace: Wrench\\Socket
  5. .. php:class:: Socket
  6. Socket class
  7. Implements low level logic for connecting, serving, reading to, and writing from WebSocket connections using PHP's streams.
  8. Unlike in previous versions of this library, a Socket instance now represents a single underlying socket resource. It's designed to be used by aggregation, rather than inheritence.
  9. .. php:const:: TIMEOUT_SOCKET
  10. Default timeout for socket operations (reads, writes)
  11. .. php:const:: DEFAULT_RECEIVE_LENGTH
  12. .. php:const:: NAME_PART_IP
  13. Socket name parts
  14. .. php:attr:: socket
  15. protected resource
  16. .. php:attr:: context
  17. protected
  18. Stream context
  19. .. php:attr:: connected
  20. protected boolean
  21. Whether the socket is connected to a server
  22. Note, the connection may not be ready to use, but the socket is connected
  23. at least. See $handshaked, and other properties in subclasses.
  24. .. php:attr:: firstRead
  25. protected boolean
  26. Whether the current read is the first one to the socket
  27. .. php:attr:: name
  28. protected string
  29. The socket name according to stream_socket_get_name
  30. .. php:attr:: options
  31. protected array
  32. .. php:attr:: protocol
  33. protected Protocol
  34. .. php:method:: configure($options)
  35. Configure options
  36. Options include
  37. - timeout_connect => int, seconds, default 2
  38. - timeout_socket => int, seconds, default 5
  39. :type $options: array
  40. :param $options:
  41. :returns: void
  42. .. php:method:: getName()
  43. Gets the name of the socket
  44. .. php:method:: getNamePart($name, $part)
  45. Gets part of the name of the socket
  46. PHP seems to return IPV6 address/port combos like this:
  47. ::1:1234, where ::1 is the address and 1234 the port So, the part number
  48. here is either the last : delimited section (the port)
  49. or all the other sections (the whole initial part, the address).
  50. :type $name: string
  51. :param $name: (from $this->getName() usually)
  52. :param $part:
  53. :returns: string
  54. .. php:method:: getIp()
  55. Gets the IP address of the socket
  56. :returns: string
  57. .. php:method:: getPort()
  58. Gets the port of the socket
  59. :returns: int
  60. .. php:method:: getLastError()
  61. Get the last error that occurred on the socket
  62. :returns: int|string
  63. .. php:method:: isConnected()
  64. Whether the socket is currently connected
  65. :returns: boolean
  66. .. php:method:: disconnect()
  67. Disconnect the socket
  68. :returns: void
  69. .. php:method:: getResource()
  70. .. php:method:: getResourceId()
  71. .. php:method:: send($data)
  72. :type $data: unknown_type
  73. :param $data:
  74. :returns: boolean|int The number of bytes sent or false on error
  75. .. php:method:: receive($length = self::DEFAULT_RECEIVE_LENGTH)
  76. Recieve data from the socket
  77. :type $length: int
  78. :param $length:
  79. :returns: string
  80. .. php:method:: __construct($options = array())
  81. Configurable constructor
  82. :param $options:
  83. .. php:method:: configureProtocol()
  84. Configures the protocol option