//这是上位机接收数据代码
public class SocketServer {
String a = "AT+CIPSTART=\"TCP\",\"192.168.191.4\",5678";
public static void main(String[] args) throws IOException {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ServerSocket listener = new ServerSocket(5678);
try {
while (true) {
//接受客户端的请求
Socket socket = listener.accept();
socket.setKeepAlive(true);
System.out.println("Client Connected");
try {
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
System.out.println(dateFormat.format(new Date()) +in.readLine());
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
out.write("2");
out.flush();
} finally {
socket.close();
}
}
} finally {
listener.close();
}
}
} |