import java.net.*;
import java.io.*;
public class DateServer {
private static int connectionCount = 0;
public static void main(String[] args) throws IOException {
try {
ServerSocket sock = new ServerSocket(6013);
System.out.println("Server started. Listening on port 6013");
while (true) {
System.out.println("Waiting for incoming connections...");
Socket client = sock.accept();
// 原子递增连接计数器
int currentConnection = ++connectionCount;
System.out.println("Accepted connection #" + currentConnection);
// 创建并启动工作线程
WorkerThread worker = new WorkerThread(client, currentConnection);
worker.start();
}
}
catch (IOException ioe) {
System.err.println("Server error: " + ioe.getMessage());
}
}
}
import java.io.*;
public class DateServer {
private static int connectionCount = 0;
public static void main(String[] args) throws IOException {
try {
ServerSocket sock = new ServerSocket(6013);
System.out.println("Server started. Listening on port 6013");
while (true) {
System.out.println("Waiting for incoming connections...");
Socket client = sock.accept();
// 原子递增连接计数器
int currentConnection = ++connectionCount;
System.out.println("Accepted connection #" + currentConnection);
// 创建并启动工作线程
WorkerThread worker = new WorkerThread(client, currentConnection);
worker.start();
}
}
catch (IOException ioe) {
System.err.println("Server error: " + ioe.getMessage());
}
}
}