// send data to the servlet
System.out.println("input"+input);
URLConnection con = getServletConnection();
OutputStream outstream = con.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstream);
oos.writeObject(input);
oos.flush();
oos.close();
// receive result from servlet
InputStream instr = con.getInputStream();
ObjectInputStream inputFromServlet = new ObjectInputStream(instr);
result= (HashMap <String,Realdata>) inputFromServlet.readObject();
inputFromServlet.close();
instr.close();
} catch (Exception ex) {
ex.printStackTrace();
}
public class IOServers implements Runnable {
boolean started = false;
ServerSocket socket = null;
public static Vector<ClientRun> userList = new Vector<ClientRun>();
public static int count = 0;
int port = 7392;
public void run() {
try {
socket = new ServerSocket(port);
started = true;
}
catch (BindException e) {
JOptionPane.showMessageDialog(Desktop.frame, "端口被其他程序占用中,程序即将退出!", "服务",JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
catch (IOException e) {
JOptionPane.showMessageDialog(Desktop.frame, "创建ServerSocket失败,程序即将退出!", "服务",JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
try {
while (started) {
Socket s = socket.accept();//监听端口
ClientRun cr = new ClientRun(s);//主线程只负责接收信息,每个客户端连接进来都会开始一个新线程
new Thread(cr).start();//把连接进来的Socket传到线程中
userList.add(cr);
}
}
catch (IOException e) {