...
}catch(BindException be){
System.out.println("Unable to bind port "+listenPort);
}catch(IOException ioe){
System.out.println("Unable to instantiate a ServerSocket on port "+listenPort);
}
....
多了个catch
}catch(BindException be){
System.out.println("Unable to bind port "+listenPort);
}catch(IOException ioe){
System.out.println("Unable to instantiate a ServerSocket on port "+listenPort);
}
....
多了个catch
stringWriter.close();你的程序先编译吧........
你的程序很怪,你是每接到一个连接,只发一个信息给对方,只从对方接收一次信息??
System.out.println("Unable to instantiate a ServerSocket on port "+listenPort);
}
---------- javac ----------
MyServer.java:33: 'class' or 'interface' expected
public void connectionhandler(Socket incoming){
^
MyServer.java:60: 'class' or 'interface' expected
}
^
MyServer.java:60: 'class' or 'interface' expected
}
^
MyServer.java:22: cannot resolve symbol
symbol : method connectionhandler (java.net.Socket)
location: class MyServer
connectionhandler(incoming);
^
4 errors
Normal Termination
输出完成(耗时 6 秒)。
public void listen(){
try{
ServerSocket server=new ServerSocket(listenPort);
Socket incoming=null;
while(true){
incoming = server.accept();
connectionhandler(incoming);
}
}catch(BindException be){
System.out.println("Unable to bind port "+listenPort);
}catch(IOException ioe){
System.out.println("Unable to instantiate a ServerSocket on port "+listenPort);
}
}//多的}
}
>>>>>
OutputStream outToSocket= incoming.getOutputStream();
唉,开始我也像是这个,可是找了半天也没找见