不知道這是TCPClient還是別的,我用網絡嗅探器來檢查服務器發送和接收的數據是什麼,數據是正確的,但是我的軟件接收不正確。我發送一個查詢字節(05)我得到一個迴應(06),然後我發送一些以9B字節開始的數據,一旦發送完成,我應該接收一個06字節,然後在那個字節之後,我應該得到一個C5字節,但是根據我的軟件,我得到另一個06字節,根據嗅探器,情況並非如此!tcpclient接收數據不正確
byte[] buff;
if (!this.isConnected())
this.connect();
NetworkStream gs = _Socket.GetStream();
gs.Write(enq, 0, enq.Length);
gs.Flush();
outputByte(enq, "Trans"); //outputs ---> 05
buff = new byte[1];
gs.Read(buff, 0, buff.Length);
gs.Flush();
outputByte(buff, "Rec");// outputs <--- 06
if (buff[0] == 0x06)
{
byte[] data = new byte[] {
0x9B, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x09,
0x67, 0x11, 0x01, 0x49, 0x4D, 0x41, 0x47, 0x45, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x53, 0x75, 0x6D, 0x6D, 0x61, 0x72, 0x79,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x08, 0x00,
0x00, 0x00, 0x1F, 0x09, 0x01, 0x00, 0x04, 0x0A, 0x10, 0x00, 0x12, 0x01, 0x1F, 0x00, 0x00, 0x00,
0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x10, 0x1E, 0x0E, 0x1E, 0x54, 0x65, 0x73,
0x74, 0x69, 0x6E, 0x67, 0x10, 0x00, 0x12, 0x01, 0x1F, 0x00, 0x00, 0x00, 0x05, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x12, 0x10, 0x0D, 0x00, 0x00, 0x90
};
outputByte(data, "Trans"); /outputs --> with above byte information
gs.Write(data, 0, data.Length);
gs.Flush();
buff = new byte[1];
gs.Read(buff, 0, buff.Length);
gs.Flush();
// this is the first receive of 06
outputByte(buff, "Rec");//outputs <--- 06
if (buff[0] == 0x06)
{
gs.Flush();
Console.WriteLine("fdsfsdfs");
byte[] resp = new byte[5];
gs.Read(resp, 0, resp.Length);
gs.Flush();
//this outputs <--- 06 but it should be showing <--- c5000100c4
outputByte(buff, "Rec");
gs.Write(ack, 0, ack.Length);
outputByte(ack, "Trans");
gs.Flush();
}
}
根據嗅探這是應該發生
---> 05
<--- 06
---> 9b008000000080000009671101494d414745310000000000000000000000000000000153756d6d617279000000000000000000000000000000000000000000000000000002080000080000001f090100040a100012011f000000050001000000000012101e0e1e54657374696e67100012011f000000050001000000000012100d000090
<--- 06
<--- c5000100c4
並根據所發生的事情
---> 05
<--- 06
---> 9b008000000080000009671101494d414745310000000000000000000000000000000153756d6d617279000000000000000000000000000000000000000000000000000002080000080000001f090100040a100012011f000000050001000000000012101e0e1e54657374696e67100012011f000000050001000000000012100d000090
<--- 06
<--- 06
任何想法的軟件,這是?此外,如果你有關於如何提高代碼的任何建議,我會感激
我要說的第一件事是:你可以輸出來自每個「Read」調用的結果。 –
@MarcGravell這就是outputByte函數所做的,這就是上面所顯示的! – Neo