java 與web服務(wù)器鏈接的實例
更新時間:2017年07月31日 14:24:30 投稿:lqh
這篇文章主要介紹了java 與web服務(wù)器鏈接的實例的相關(guān)資料,使用net.Socket類sock.getInetAddress()方法獲得與Web服務(wù)器連接,需要的朋友可以參考下
java 與web服務(wù)器鏈接的實例
解決方法
下面的例子演示了如何通過使用net.Socket類sock.getInetAddress()方法獲得與Web服務(wù)器連接。
import java.net.InetAddress; import java.net.Socket; public class WebPing { public static void main(String[] args) { try { InetAddress addr; Socket sock = new Socket("www.yiibai.com", 80); addr = sock.getInetAddress(); System.out.println("Connected to " + addr); sock.close(); } catch (java.io.IOException e) { System.out.println("Can't connect to " + args[0]); System.out.println(e); } } }
結(jié)果
上面的代碼示例將產(chǎn)生以下結(jié)果。
Connected to http://www.yiibai.com/112.124.103.85
以上就是使用java 與web 服務(wù)器鏈接的實例如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
詳解Java8與Runtime.getRuntime().availableProcessors()
這篇文章主要介紹了詳解Java8與Runtime.getRuntime().availableProcessors(),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06spring cloud升級到spring boot 2.x/Finchley.RELEASE遇到的坑
這篇文章主要介紹了spring cloud升級到spring boot 2.x/Finchley.RELEASE遇到的坑,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-08-08