看板 java 關於我們 聯絡資訊
getInetAddress public InetAddress getInetAddress() Returns the address to which the socket is connected. Returns: the remote IP address to which this socket is connected, or null if the socket is not connected. 為什麼我使用上面那個函數, 回傳值是/127.0.0.1 就是為什麼會多一個"/" 我從API裡面沒看出來有敘述? ps.要把"/"處理掉很容易,只是想知道原因 還是跟IDE有關係呢? >如果問的問題很蠢請見諒,沒有goo到...< -- ┌這?─────────────────────────────┐ │ │ 一"一 \ / >\\\< ╯ ╰ ∩ ∩ ▁ ▁_< ㄧ ㄧ+ │ ε Δ ╰╯ 北七 亂喔 害羞 莎笅 爽啦 哭爸 XD 科科 └──────────────────────────────────────┘ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.136.104.228
sbrhsieh:回傳值是 InetAddress,並沒有說是 IP "字串" 12/13 01:43
sbrhsieh:請再去看看 InetAddress API doc. 12/13 01:45
**找到這個→The string returned is of the form: hostname / literal IP address. 是因為InetAddress覆寫的toString()把ip加上/輸出嗎? 剛測試了其他,也都會帶"/" System.out.println(client.getInetAddress()); System.out.println(client.getLocalAddress()); System.out.println(client.getLocalPort()); System.out.println(client.getLocalSocketAddress()); System.out.println(client.getRemoteSocketAddress()); 另外想問,getLocalPort()這個回傳的port 是用在哪裡的? 最後謝謝大大回答, 好久沒寫了,怎麼記得以前回傳ip不會帶"/" >< ※ 編輯: polomoss 來自: 220.136.104.228 (12/13 02:00)