【发布时间】:2014-04-26 18:58:49
【问题描述】:
我有一个硬件而不是加入到 ad hoc 网络中的笔记本电脑(服务器)。
当服务器单独发送数据时,它可以正常工作。并且客户端单独发送数据,也可以正常工作。
但是当服务器和客户端一起发送数据时,经过一段时间,就会发生超时。
在 35 之后,有时会出现 33 包超时。
我更改了硬件的传输速率,但它也断开了连接。
虽然硬件支持全双工。
超时后,我 ping 硬件,它不在端口上。
并检查服务器上的端口,它是开放的。
我该怎么办?
byte[] bytes = new byte[512];
//try
//{
IPHostEntry ipHost = Dns.GetHostEntry("");
// Gets first IP address associated with a localhost
IPAddress add = ipHost.AddressList[3];
TcpListener tcpListener = new TcpListener(add, 6000);
tcpListener.Start();
TcpClient tcpClient = tcpListener.AcceptTcpClient();
NetworkStream stream = tcpClient.GetStream();
String data = null;
while (true)
{
int j = 0;
int i;
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
j = j + 1;
// Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
AddItem("j="+j+" Received:"+ data);
// Process the data sent by the client.
//data = data.ToUpper();
byte[] msg = System.Text.Encoding.ASCII.GetBytes("thanks");
// Send back a response.
stream.Write(msg, 0, msg.Length);
AddItem("Sent:"+"thanks");
}
// Shutdown and end connection
tcpClient.Close();
【问题讨论】:
标签: c#