> Jeff Donner wrote:
>> NetConnection::getNetAddress() and NetConnection::getNetAddressString()
>> both refer to the remote side; is there an easy way to
>> get the address (IP:port) of /this/ side?
Mark Frohnmayer wrote:
> The Socket::getInterfaceAddresses function gets the list of
> locally bindable addresses.
Ok, thanks, but that doesn't give the port, which wouldn't
distinguish between possibly many connections from the same
machine.
I've done the following and it works for what I need but,
I'm a little surprised the information is not incorporated
somehow into NetConnection. Oh well:
From the example TestNetInterface::handleInfoPacket(...),
(with couts added) in the client part ('this' end):
cout << "ADDRESSES:" << endl;
TNL::Vector<TNL::Address> addresses;
TNL::Socket::getInterfaceAddresses(&addresses);
for (int i = 0; i < addresses.size(); ++i) {
cout << "address: " << addresses[i].toString() << endl;
}
TNL::Address b = getFirstBoundInterfaceAddress();
cout << "FIRST BOUND: " << b.toString() << endl;
output:
ADDRESSES:
address: IP:192.168.0.8:0
FIRST BOUND: IP:192.168.0.8:33513
From the function, in the server part upon connection
(remote end):
cout << "CLIENT ADDRESS: " << address.toString() << endl;
output:
CLIENT ADDRESS: IP:192.168.0.8:33513
Of course, this probably wouldn't work if there were more
than one connection to the server (which connection would
be the first?) but it works for what I need.
Thanks again,
Jeff
|