標籤:test row 表示 網路通訊 針對 throw get static str
簡介:
連接埠:1
1.用於區別不同的應用程式。
2. 連接埠號碼範圍0~65535 ,0~1023為系統所保留。
3.IP 位址和 連接埠號碼組成了Socket .Socket 是網路啟動並執行程式之間雙向通訊鏈路的終點,是TCP 和UDP的基礎。
4.常見的連接埠號碼 http 80 ftp:21 telnet 23
Java 中的網路支援:
針對網路通訊的不同層次,分為四類
1.InetAddress ,用於表示網路上的硬體類(標識IP地址相關資訊)
2.URL:網路資源定位
3.Sockets :用於TCP
4.Datagram :用於UDP
package com.InetAddress;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
public class Test1 {
public static void main(String[] args) throws UnknownHostException{
InetAddress address = InetAddress.getLocalHost();
System.out.println("電腦名稱字: " + address.getHostName());
System.out.println("電腦的地址:" + address.getHostAddress());
byte[] bytes = address.getAddress();//擷取位元組數組形式的IP
System.out.println(Arrays.toString(bytes));
System.out.println(address);
//InetAddress address2 = InetAddress.getByAddress(bytes);
//InetAddress address2 = InetAddress.getByName("");
//System.out.println(address2.getHostAddress());
}
}
Java Socket 編程