C类地址(192.0.0.0-223.255.255.0):192.168.0.0~192.168.255.255
InetAddress类 无构造方法 getLocalHost获取本地ip getByName获取网络主机名
基于tcp:Socket(客户端)和Server Socket(服务器端)
ServerSocket.accept():获取客户端socket
Socket通信模型
进行网络通信是,Socket需要借助数据流来完成数据的传递工作
Socket类
两个Socket类的构造方法及其含义
Socket socket=new Socker(“localhost”,8800)
ServerSocket serverSocket = new ServerSocket(9000);
socket.getOutputStream();
os.write
1.建立连接
2.打开Socket关联的输入输出流
3.数据流中读写信息
4.关闭所有的数据流和Socket
ServerSocket类的accept()方法有何用处:获取客户端socket
import java.net.InetAddress; import java.net.UnknownHostException; public class TestAddress { public static void main(String[] args) throws UnknownHostException { //InetAddress:IP地址包装类 InetAddress localHost = InetAddress.getLocalHost(); System.out.println(localHost.getHostAddress());//ip地址 System.out.println(localHost.getHostName());//主机名 //得到网络主机名 InetAddress address = InetAddress.getByName("www.baidu.com"); System.out.println(address.getHostAddress()); System.out.println(address.getHostName()); } }
原创文章,作者:wdmbts,如若转载,请注明出处:https://blog.ytso.com/275481.html