67,514
社区成员
发帖
与我相关
我的任务
分享
//处理端口号冲突
if (args.length < 1 ) {
ss = new ServerSocket(8001);
} else {
ss = new ServerSocket(Integer.parseInt(args[0]));
}
boolean bRunning = true;
while(bRunning){
Socket s= ss.accept();
new Thread(new serverStart(s)).start();
}
private Socket s = null;
InputStream ips;
OutputStream ops;
private volatile boolean running = true;
public serverStart(Socket s) throws IOException {
this.s = s;
ips = s.getInputStream();
ops = s.getOutputStream();
}
public void run(){
while(running){
try {
Message m = read();
System.out.println("收到信息");
} catch (Exception e) {
e.printStackTrace();
}
}
try {
if(s!=null)s.close();
} catch (IOException e) {
}
}