这里的ServerSocket有没有象VC中的LISTEN(5),就是可以等待多个客户的连接??? 下面的NEW 为什么不成功? public class ServerThread extends Thread { public int iPort = 8888 ; public String sName = "default"; //public Socket S; public ServerSocket S; public ServerThread(String sName, int iPort) { this.sName = sName; this.iPort = iPort; setSocket(); }
private void setSocket() { S = new ServerSocket(iPort); //???这里有错? 不能NEW } } 错误信息: ServerThread.java:20: unreported exception java.io.IOException; must be caught o r declared to be thrown S = new ServerSocket(iPort); ^ 有分给了,谢谢!
下面的NEW 为什么不成功?
public class ServerThread extends Thread {
public int iPort = 8888 ;
public String sName = "default";
//public Socket S;
public ServerSocket S; public ServerThread(String sName, int iPort)
{
this.sName = sName;
this.iPort = iPort;
setSocket();
}
private void setSocket()
{
S = new ServerSocket(iPort); //???这里有错? 不能NEW
}
}
错误信息:
ServerThread.java:20: unreported exception java.io.IOException; must be caught o
r declared to be thrown
S = new ServerSocket(iPort);
^
有分给了,谢谢!
}或者
在setSocket()方法里面try{
=new ServerSocket(iPort);
}
catch(Exception e){}必须如此因为有可能产生违例