ConnectionInterface.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * This file is part of workerman.
  4. *
  5. * Licensed under The MIT License
  6. * For full copyright and license information, please see the MIT-LICENSE.txt
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @author walkor<walkor@workerman.net>
  10. * @copyright walkor<walkor@workerman.net>
  11. * @link http://www.workerman.net/
  12. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace Workerman\Connection;
  15. /**
  16. * ConnectionInterface.
  17. */
  18. abstract class ConnectionInterface
  19. {
  20. /**
  21. * Statistics for status command.
  22. *
  23. * @var array
  24. */
  25. public static $statistics = array(
  26. 'connection_count' => 0,
  27. 'total_request' => 0,
  28. 'throw_exception' => 0,
  29. 'send_fail' => 0,
  30. );
  31. /**
  32. * Emitted when data is received.
  33. *
  34. * @var callback
  35. */
  36. public $onMessage = null;
  37. /**
  38. * Emitted when the other end of the socket sends a FIN packet.
  39. *
  40. * @var callback
  41. */
  42. public $onClose = null;
  43. /**
  44. * Emitted when an error occurs with connection.
  45. *
  46. * @var callback
  47. */
  48. public $onError = null;
  49. /**
  50. * Sends data on the connection.
  51. *
  52. * @param string $send_buffer
  53. * @return void|boolean
  54. */
  55. abstract public function send($send_buffer);
  56. /**
  57. * Get remote IP.
  58. *
  59. * @return string
  60. */
  61. abstract public function getRemoteIp();
  62. /**
  63. * Get remote port.
  64. *
  65. * @return int
  66. */
  67. abstract public function getRemotePort();
  68. /**
  69. * Get remote address.
  70. *
  71. * @return string
  72. */
  73. abstract public function getRemoteAddress();
  74. /**
  75. * Get local IP.
  76. *
  77. * @return string
  78. */
  79. abstract public function getLocalIp();
  80. /**
  81. * Get local port.
  82. *
  83. * @return int
  84. */
  85. abstract public function getLocalPort();
  86. /**
  87. * Get local address.
  88. *
  89. * @return string
  90. */
  91. abstract public function getLocalAddress();
  92. /**
  93. * Is ipv4.
  94. *
  95. * @return bool
  96. */
  97. abstract public function isIPv4();
  98. /**
  99. * Is ipv6.
  100. *
  101. * @return bool
  102. */
  103. abstract public function isIPv6();
  104. /**
  105. * Close connection.
  106. *
  107. * @param $data
  108. * @return void
  109. */
  110. abstract public function close($data = null);
  111. }