2.serversocket的建立和使用:
新建一个javaproject 然后新建一个class:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JOptionPane;
public class MyServer {
public static void main(String[] args) throws Exception {
ServerSocket server=new ServerSocket(12345);
Socket client =server.accept();//会阻塞main线程,一般不这么用。
JOptionPane.showMessageDialog(null, "有客户端链接到了本机的12345端口");
client.close();
server.close();
}
}
运行后,在浏览器输入:
标签:通讯,java,socket,io,server,ServerSocket,安卓中,close,import From: https://blog.51cto.com/u_15866446/5845542