您好,登錄后才能下訂單哦!
網(wǎng)絡(luò)編程:跟服務(wù)器底層源碼有關(guān)
B/S在公網(wǎng)上(瀏覽器訪問)服務(wù)器端和客戶端只寫一端,c/s在局域網(wǎng)上(網(wǎng)吧)服務(wù)器端和客戶端都要寫,B/S是大大的C/S
協(xié)議:端口之間的交流更暢通,不同軟件有各自的端口
tcp/udp/http
ip:定位一個(gè)節(jié)點(diǎn)
使用靜態(tài)方法getLocalHost方法創(chuàng)建InetAddress對(duì)象,InetAddress沒有構(gòu)造器
InetAddress addr = InetAddress.getLocalHost();
addr.getHostAddress() 本機(jī)地址
addr.getHostName() 計(jì)算機(jī)名
public class http {
public static void main(String[]args) throws UnknownHostException
{
//使用靜態(tài)方法getLocalHost方法創(chuàng)建InetAddress對(duì)象
InetAddress addr = InetAddress.getLocalHost();
System.out.println(addr.getHostAddress());
System.out.println(addr.getHostName());
//使用域名得到InetAddress對(duì)象
addr=InetAddress.getByName("www.163.com");
System.out.println(addr.getHostAddress());//返回163服務(wù)器的ip
System.out.println(addr.getHostName());//輸出服務(wù)器名
//根據(jù)ip地址得到InetAddress對(duì)象
addr=InetAddress.getByName("118.118.221.77");
System.out.println(addr.getHostAddress());
System.out.println(addr.getHostName());//若ip地址不存在或者DNS不允許,則返回ip地址而不是域名
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。