Consultor Eletrônico



Kbase P114232: Application using 4GL Socket does not read all the data
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   11/5/2009
Status: Verified

SYMPTOM(s):

Application using 4GL Socket does not read all the data

The number at bytes available at the 4GL Socket is incorrect

A 4GL Socket connection returns 0 bytes in the read handler procedure

FACT(s) (Environment):

Using the GET-BYTES-AVAILABLE() method in a loop to determine the amount of bytes to read
The 4GL Socket application is communicating with a Web Server
All Supported Operating Systems
Progress 9.1x
OpenEdge 10.x

CAUSE:

The Web Server is sending the response in multiple TCP packets. If the loop in which data is read goes too fast, then the next TCP packet is missed.

FIX:

Specify a timeout for the READ() method and read the data until the BYTES-READ attribute returns 0.
The following is not a complete working sample, but it illustrates the method:

vSocket:SET-SOCKET-OPTION("SO-RCVTIMEO", '5').

SET-SIZE(mBuffer) = iBuf + 1.
SET-BYTE-ORDER(mBuffer) = BIG-ENDIAN.
vSocket:READ(mBuffer, 1, iBuf, 1) NO-ERROR.
cStr = cStr + GET-STRING(mBuffer,1).
SET-SIZE(mBuffer) = 0.

iLength = vSocket:BYTES-READ.
tLength = iLength.

IF iLength > 0 THEN
DO:
DO WHILE iLength > 0.
SET-SIZE(mBuffer) = iBuf + 1.
SET-BYTE-ORDER(mBuffer) = BIG-ENDIAN.
vSocket:READ(mBuffer, 1, iBuf, 1) NO-ERROR.
cStr = cStr + GET-STRING(mBuffer,1).
SET-SIZE(mBuffer) = 0.
iLength = vSocket:BYTES-READ.
tLength = tLength + iLength.
END.