if ((tcpClient.Connected == true))
{
int clientCount = Interlocked.Increment(ref clients);
NetworkStream clientStream = tcpClient.GetStream();
ASCIIEncoding encoder = new ASCIIEncoding();
//Console.WriteLine("Client connected. ({0} connected)", clientCount);
StringBuilder myCompleteMessage = new StringBuilder();
if (clientStream.CanRead)
{
byte[] myReadBuffer = new byte[1024];
int numberOfBytesRead = 0;
// Incoming message may be larger than the buffer size.
try
{
do
{
System.Threading.Thread.Sleep(1000);
numberOfBytesRead = clientStream.Read(myReadBuffer, 0, myReadBuffer.Length);
myCompleteMessage.AppendFormat("{0}", Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead));
}
while (clientStream.DataAvailable);
}
catch (Exception ex)
{
tcpClient.Close();
}
}
}
我正在研究车辆跟踪系统。我把这段代码作为listner 我尝试从车辆跟踪设备读取数据当我通过客户端(本地机器/ PC)发送时我获取数据但是它无法从设备读取数据 感谢