把服务端产生的客户线程(每个客户一个线程)保存在Vector或Hashtable中,用客户IP或用户ID来唯一确定。
每一个客户线程中应该保存有服务端与客户连接的Socket,这样就可以在客户线程中实现消息传送。while (true)//接受多个用户
{
try
{
if(mServerSocket != null)
{
mServerSocket.setSoTimeout(300);//waiting 100 ns
mSocket = mServerSocket.accept();
mServerSocket.setSoTimeout(0);
}
else
{return false;}
}
catch(Exception timeoutE)
{}
ProCustomer pc= new ProCustomer (this,mSocket);
cConnectionOne.start();
每一个客户线程中应该保存有服务端与客户连接的Socket,这样就可以在客户线程中实现消息传送。while (true)//接受多个用户
{
try
{
if(mServerSocket != null)
{
mServerSocket.setSoTimeout(300);//waiting 100 ns
mSocket = mServerSocket.accept();
mServerSocket.setSoTimeout(0);
}
else
{return false;}
}
catch(Exception timeoutE)
{}
ProCustomer pc= new ProCustomer (this,mSocket);
cConnectionOne.start();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货