标签:ack 表达式 java hang system.in 自己 bubuko nts input
结对编程:1人负责客户端,一人负责服务器
客户端部分的截图在我的结对搭档的博客里面
Server_2.java
import java.io.*;
import java.net.*;
import java.util.*;
public class Server_2 {
public static void main(String[] args) {
final int port=5353;
ServerSocket Server_2forClient_2=null;
Socket SocketOnServer_2=null;
DataOutputStream Server_2out=null;
DataInputStream Server_2in=null;
try {
Server_2forClient_2=new ServerSocket(port);
}
catch (IOException e1) {
System.out.println(e1);
//e1.printStackTrace();
}
try {
System.out.println("等待客户端呼叫……");
SocketOnServer_2=Server_2forClient_2.accept();
Server_2out=new DataOutputStream(SocketOnServer_2.getOutputStream());
Server_2in=new DataInputStream(SocketOnServer_2.getInputStream());
String s=Server_2in.readUTF();
System.out.println("服务器接收到表达式:"+s);
String expr;
int result;
MyBC mybc=new MyBC();
mybc.setExpression(s);
expr=mybc.changedWay();
result=mybc.evaluate(expr);
Server_2out.writeUTF("中缀表达式“"+s+"”转后缀表达式“"+expr+",运算结果为:"+result);
//Thread.sleep(500);
}
catch (Exception e2) {
System.out.println("客户端已断开"+e2);
}
}
}
Client_2.java
import java.io.*;
import java.net.*;
import java.util.*;
public class Client_2 {
public static void main(String[] args) {
final int port=5353;
final String host="172.30.4.50";
Socket Client_2Socket;
DataInputStream Client_2in=null;
DataOutputStream Client_2out=null;
String expr;
Scanner scanner=new Scanner(System.in);
System.out.println("请输入表达式:");
expr=scanner.nextLine();
try {
Client_2Socket=new Socket(host,port);
Client_2in=new DataInputStream(Client_2Socket.getInputStream());
Client_2out=new DataOutputStream(Client_2Socket.getOutputStream());
Client_2out.writeUTF(expr);
String s=Client_2in.readUTF();
System.out.println("服务器回复:\n"+s);
}
catch (Exception e) {
System.out.println("服务器已断开"+e);
}
}
}
标签:ack 表达式 java hang system.in 自己 bubuko nts input
原文地址:https://www.cnblogs.com/xpl20165321/p/9096488.html