The getPort() currently only returns the "port" part and explicitly omits the listening IP. This has been documented as of v0.4.4 and has in fact been like this ever since this method has been added.
This PR replaced this method with a getAddress() method that it returns the full remote address, i.e. IP and port.
- echo $server->getPort(); - 8000 + echo $server->getAddress(); + 192.168.0.12:8000
This is obviously a BC break, so I've made sure to add documentation on how to get only the port from the full address with a one-liner.
Empirical evidence seems to suggest the old getPort() method isn't used that much and is mostly used in a context where the full URI likely makes more sense anyway. For TCP/IP based servers, the full URI contains the port and with the above one-liner this switch should be easy.
There are plenty of reasons, let me try to list a few here:
- URIs are literally the only way to provide a consistent addressing scheme throughout React's components, see Consistent addressing scheme reactphp#199
- Not all protocols know the concept of a "port", for example the future UNIX server does not use IP/port, but a UNIX filessystem path ([Server] Add support for Unix domain sockets (UDS) #25, Add support for Unix domain sockets (UDS) #17)
- Consistency with the Datagram component (Properly format IPv6 addresses and return null for unknown addresses datagram#14)
- Consistency with the SocketClient component (Use
connect($uri)instead ofcreate($host, $port)reactphp-legacy/socket-client#74) - Consistency throughout this project (Return full remote address instead of only IP #65 and Also expose port for each connection #26)