What does Java InetSocketAddress look like .toString()?

你离开我真会死。 提交于 2021-02-05 08:06:26

问题


I'm doing a .toString() on an InetSocketAddress. This is part of an Android websocket client that so far is failing to connect to the host.

Right now the output from a variable address.toString() looks like domain.com/72.xx.xxx.xx:8000 but from what I understand there needs to be two values (IP and port) only?

Thanks letting me know if this looks correct.


回答1:


The toString() of InetSocketAddress first calls the toString() of InetAddress and then appends the port number to it and the string returned from toString() of InetAddress is of the form: hostname / literal IP address.

Later port number is concatenated before returning from the InetSocketAddress's toString() to the returned value (from the toString() of InetAddress), hence the final result is hostname / literal IP address:port number.

For more information see the JavaDocs for InetSocketAddress's toString().




回答2:


Was able to find an example: http://discuss.itacumens.com/index.php?topic=46099.0

Basically it is correct :)

I'll need to debug elsewhere...



来源:https://stackoverflow.com/questions/10646857/what-does-java-inetsocketaddress-look-like-tostring

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!