题目:服务器是显示汇率的,然后从客户端的界面输入一个金额传给服务器,服务器接受计算后将结果传回客户端,客户端再显示到界面上.我的在客户端页面输入数据点计算之后界面都要用任务管理器关了......绝望.jpg
服务器:
public void start()
{
try {
serverSocket = new ServerSocket(113);
Socket socket = serverSocket.accept();
DataInputStream input = new DataInputStream(socket.getInputStream());
String clientInputStr = input.readUTF();
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
String result=String.valueOf(Float.valueOf(text_rate.getText())*Integer.parseInt(clientInputStr));
out.writeUTF(result);
} catch (IOException e) {
e.printStackTrace();
}
}
客户端:if(ev.getSource()==button_cal);
{
try
{
DataInputStream input = new DataInputStream(socket.getInputStream());
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
String str = new BufferedReader(new InputStreamReader(System.in)).readLine();
out.writeUTF(str);
String ret = input.readUTF();
text_m2.setText(ret);
socket.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}