The getRemoteAddress() currently only returns the IP part and explicitly omits the port. 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 changes this so that it returns the full remote address, i.e. IP and port.
echo $conn->getRemoteAddress();
- 192.168.0.12 + 192.168.0.12:41761
This is obviously a (minor?) BC break, so I've made sure to add documentation on how to get only the IP from the full address with a one-liner.
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 (Replace listen() call with URIs passed to constructor #61)
- Fixes / closes Also expose port for each connection #26