主题:网络C/S编程问题,高手进给个思路
请问高手,我想写个C/S程序,支持多用户同时接入,并同时处理多用户消息,但我用AcceptSocket()始终只能接受一个用户的数据我的代码是:
try
{
gameserver=new TcpListener(ipAddress,iport);
gameserver.Start();
statusBar1.Text="正在等待连接......";
while(true)
{
socket=gameserver.AcceptSocket();
listBox2.Items.Add(socket.RemoteEndPoint.ToString()+":大笑着走了进来");
while(true)
{
networkStream = new NetworkStream (socket1[i]) ;
//从当前数据流中读取一行字符,返回值是字符串
streamReader = new StreamReader ( networkStream ) ;
listBox2.Items.Add ( socket.RemoteEndPoint.ToString()+"说:" + streamReader.ReadLine()) ;
}
}
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
try
{
gameserver=new TcpListener(ipAddress,iport);
gameserver.Start();
statusBar1.Text="正在等待连接......";
while(true)
{
socket=gameserver.AcceptSocket();
listBox2.Items.Add(socket.RemoteEndPoint.ToString()+":大笑着走了进来");
while(true)
{
networkStream = new NetworkStream (socket1[i]) ;
//从当前数据流中读取一行字符,返回值是字符串
streamReader = new StreamReader ( networkStream ) ;
listBox2.Items.Add ( socket.RemoteEndPoint.ToString()+"说:" + streamReader.ReadLine()) ;
}
}
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}