帮忙看下为什么会进入catch(ConnectionNotFoundException cnfe) 里面,
try{
sc=(SocketConnection) Connector.open("socket://localhost:5009");
//sc=(SocketConnection) scn.acceptAndOpen();
si.setText("Connection to server");
is=sc.openInputStream();
os=sc.openOutputStream();
sender=new Sender(os);
//f.addCommand(sendCommand);
//死循环,用来读取服务器发送的数据
while(true)
{
StringBuffer sb = new StringBuffer();
int c=0;
while (((c=is.read())!='\n') && (c!=-1))
{
sb.append((char)c);
}
if(c==-1)
{
break;
}
//显示接收到的消息
si.setText("Message receiver-"+sb.toString());
}
stop();
si.setText("Connection is closed");
f.removeCommand(sendCommand);
}catch(ConnectionNotFoundException cnfe) {
Alert a =new Alert("Client","Port 5000 is already taken",null,AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
a.setCommandListener(this);
display.setCurrent(a);
}