服务端代码
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
/**
* ===========================
* Author:多测师_何sir
* Time:2020-07-14 17:55
* Wechat:18665861277
* website:www.duoceshi.cn
* ===========================
**/
public class Server {
public static void main(String[] args) throws IOException {
//设置服务器的端口
ServerSocket serverSocket = new ServerSocket(8888);
System.out.println("服务端已启动就绪");
//只有服务器被客户连接之后,才会执行后面的语句,此方法在连接传入之前一直阻塞。
Socket socket = serverSocket.accept();
// 接收到连接后启动线程,用来接收客户端的消息
Thread thread = new Thread(new ServerRunnable(socket));
thread.start();
// 向客户端发送消息
OutputStreamWriter osw = new OutputStreamWriter(socket.getOutputStream(),