我想在Delphi 2007中使用Indy10 ReadBytes()來讀取格式爲[#bytes] \ r \ n的一系列數據段的大量下載,其中#bytes指示字節數。我的算法是:Indy 10 IdTCPSever讀取字節加擾數據
- 使用ReadBytes()獲取[#] \ r \ n文本,通常爲10個字節。
- 使用ReadBytes()獲取指定的#個數據字節。
- 如果需要處理更多數據段,即#爲負,請轉至步驟1。
這種運作良好,但常常我不明白,在步驟1中預期的文本這裏的後330個成功的數據段很短的例子:
數據從最後一步收到2的ReadBytes()。注意嵌入步驟1 [-08019] \ r \ n文本。
Line|A033164|B033164|C033164|D033164|E033164|F033164|G033164|H033164|EndL\r|Begin
Line|A033165|B033165|C033165|D033165|E033165|F033165|G033165|H033165|EndL\r|Begin
Line|A033166|B033166|C033166|D033166|E033166|F033166|G033166|H033166|EndL\r[-08019]
\ r \ n |開始 線| A033167 | B033167 | C033167 | D033167 | E033167 | F033167 | G033167 | H033167 | ENDL \ r |開始 線| A033168 | B033168 | C033168 | D033168 | E033168 | F033168 | G033168 | H033168 | ENDL \ r |首先是Wireshark捕獲
套接字數據。
0090 30 33 33 31 36 36 7c 42 30 33 33 31 36 36 7c 43 033166|B033166|C
00a0 30 33 33 31 36 36 7c 44 30 33 33 31 36 36 7c 45 033166|D033166|E
00b0 30 33 33 31 36 36 7c 46 30 33 33 31 36 36 7c 47 033166|F033166|G
00c0 30 33 33 31 36 36 7c 48 30 33 33 31 36 36 7c 45 033166|H033166|E
00d0 6e 64 4c 0d ndL.
號時間源目標協議長度信息
2837 4.386336000 000.00.247.121 000.00.172.17 TCP 1514 40887 > 57006 [ACK] Seq=2689776 Ack=93 Win=1460 Len=1460
Frame 2837: 1514 bytes on wire (12112 bits), 1514 bytes captured (12112 bits) on interface 0
Ethernet II, Src: Cisco_60:4d:bf (e4:d3:f1:60:4d:bf), Dst: Dell_2a:78:29 (f0:4d:a2:2a:78:29)
Internet Protocol Version 4, Src: 000.00.247.121 (000.00.247.121), Dst: 000.00.172.17 (000.00.172.17)
Transmission Control Protocol, Src Port: 40887 (40887), Dst Port: 57006 (57006), Seq: 2689776, Ack: 93, Len: 1460
Data (1460 bytes)
0000 5b 2d 30 38 30 31 39 5d 0d 0a 7c 42 65 67 69 6e [-08019]..|Begin
0010 20 4c 69 6e 65 7c 41 30 33 33 31 36 37 7c 42 30 Line|A033167|B0
0020 33 33 31 36 37 7c 43 30 33 33 31 36 37 7c 44 30 33167|C033167|D0
0030 33 33 31 36 37 7c 45 30 33 33 31 36 37 7c 46 30 33167|E033167|F0
有誰知道爲什麼會這樣?謝謝
更多信息。我們在單線程中進行套接字讀取,並且在讀取時不要調用Connected()。下面是相關的代碼片段:
AClientDebugSocketContext.Connection.Socket.ReadBytes(inBuffer,byteCount,True);
numBytes := Length(inBuffer);
Logger.WriteToLogFile(BytesToString: '+BytesToString(inBuffer,0,numBytes),0);
Move(inBuffer[0], Pointer(Integer(Buffer))^, numBytes);
請顯示一些代碼。 –
爲什麼在步驟1中使用ReadBytes()而不是ReadLn()?當[#]是負值時,這意味着什麼? –