启动端
/**
* 套接字(Socket)通信
* @throws IOException
*/
public static void MySaver() throws IOException {
// 1.创建一个服务器端Socket,即ServerSocket,指定绑定的端口,并监听
ServerSocket serverSocket = new ServerSocket(65431);
System.out.println("***服务器即将启动,等待客服端连接***");
Socket socket = null;
while (true) {
// 2.调用accept()方法开始监听,等待客服端的连接
socket = serverSocket.accept();
//创建一个新线程
ServerThread serverThread = new ServerThread(socket);
//启动线程
serverThread.start();
//获取客服端IP
InetAddress address = socket.getInetAddress();
System.out.println("当前客服端的IP:"+address.getHostAddress());
}