帮忙看下为什么会进入catch(ConnectionNotFoundException cnfe) 里面,

TM_LiuYan 2009-11-06 09:22:32
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);

}
...全文
97 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zoujuezoujue 2010-11-11
  • 打赏
  • 举报
回复
什么情况...
TM_LiuYan 2009-11-08
  • 打赏
  • 举报
回复
发重了,上个已经结贴,这个还是给大家结了吧。
gesanri 2009-11-07
  • 打赏
  • 举报
回复
你先别读取数据,先看看能否连接,或者换个端口试试
97095639 2009-11-07
  • 打赏
  • 举报
回复
jf
Sodino 2009-11-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 yitiaochongzi 的回复:]
看看服务器端得监听有没有问题  Socket s = new ServerSocket(5009).accept();
[/Quote]


javame中没有Socket,只有socket。

请楼主确保服务端发布了服务及端口号正确与否。



或将localhost改成127.0.0.1试试。
yitiaochongzi 2009-11-07
  • 打赏
  • 举报
回复
看看服务器端得监听有没有问题 Socket s = new ServerSocket(5009).accept();
阁楼上的伟哥 2009-11-06
  • 打赏
  • 举报
回复
哇塞你分好多啊。
重复发帖
你再每句 后面加上
System.out.println("_______");
看看到哪里 没有输入说明那句有问题。
这是调试的方法哦。

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧