1.代码:
package com.jikexueyuan.testmyserversocket.main;
import java.io.IOException;
import java.net.ServerSocket;
import javax.swing.JOptionPane;
public class MyServerSocket {
public static void main(String[] args) {
// 1-65535
try {
ServerSocket serverSocket = new ServerSocket(12345);//服务器启动监听了12345
serverSocket.accept();//等待客户端连接12345端口
JOptionPane.showMessageDialog(null, "有客户端链接到了本机的12345端口");
} catch (IOException e) {
e.printStackTrace();
}
}
}
2.运行之后打开浏览器输入127.0.0.1:12345