Socket广播问题请教大家?急!

服务端接受连接是建立处理线程,并将此线程加入队列中
[code]
public void run() {
try {
int i = 1;
while (true) {
Socket client = listen.accept();
System.out.println("Thread...." + i); // count spawn
ThreadedEchoHandler r = new ThreadedEchoHandler(this,client, i);
r.start();
i++;

// 添加到客户端队列中
connections.addElement(r);
}
} catch (IOException e) {
e.printStackTrace();
}

}
[/code]

当服务器接受到客户端消息的时候广播发送信息
[code]
public void broadCast(String msg) throws IOException {
int i;

for (i = 0; i < connections.size(); i++) {

ThreadedEchoHandler thread = (ThreadedEchoHandler) connections.elementAt(i);
//向客户端输出消息
thread.out.writeUTF("BroadCast:"+"Client "+thread.counter+":"+msg);
System.out.println(thread.counter);
}
}
[/code]
客户端接受数据
[code]
while (true) {
String str = wt.readLine();
out.writeUTF("client send:" + str);
if (str.equals("end")) {
break;
}
System.out.println(in.readUTF());
}
[/code]
问题就在这里,此循环里面System.out.println(thread.counter);可以正常输出,但是writeUTF没有正常执行,测试结果只有刚刚发送消息的那个客户端接受到回应,其他的就没了,请教大家,帮忙看看
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值