日期:2014-05-17  浏览次数:20925 次

C# Tcp客户端与服务端通信问题
请帮忙看看这个段代码 这个是服务端的侦听部分
现在遇到的问题是
 
A客户端连接后 通信正常 然后不关闭程序A 连接也没Close
B客户端连接后 通信也正常 同样不关闭程序B 连接也没Close

然后继续发送数据的话服务端就只能接收到B客户端的了 A客户端发送的数据接收不到了 但是A客户端确实是把数据发送出去了

public static void Main (string[] args)
{
Console.WriteLine(ServerName);
Console.WriteLine(ip);
Console.WriteLine(port);

client = new TcpClient();

theadLisener=new Thread(new ThreadStart(ServerStart));
theadLisener.Start();
}

public static void ServerStart()
{
listener =new TcpListener(ip,port);
listener.Start();
Console.WriteLine("服务正在监听...");
while(true)
{
if (listener.Pending()) 
{
client = listener.AcceptTcpClient();
// client= listener.AcceptSocket();
clientservice= new Thread(new ThreadStart(Clients));
clientservice.Start();
}
}
}

public static void Clients()
{
Newonline = new RemoteClient(client);
}