Joined: 20 Nov 2008 Posts: 47 Location: the Netherlands
Posted: Mon May 30, 2022 7:34 pm Post subject: socketstat issue
I just found the strangest thing in a code i've been using for several projects.
When I connect to a server the socketstat data get's zero but I'm sure the buffer still contains data.
Code:
Do
Tempw =Socketstat(idy , Sel_recv)' get received bytes print"socketstat size: ";tempw ‘debug the tempw datasize If Tempw >0Then' if there is something received
Wresult2 =Tcpread(idy, Incomingtcp) ‘read the data Print incomingtcp ‘print the datafordebug End if
loopuntil tempw =0 ‘end the loopon zero bytes
print “end of loop” ‘debugforloopend
now the buffer still contains data and the tempw stays zero. Even when new data is send by the remote connection.
So there is no other way to clear the buffer than to reset the socket (close and reopen it). But that means I loose data that I don't want.
Now what I added as a sort off bug fix is following:
Code:
Do
Tempw =Socketstat(idy , Sel_recv)' get received bytes print"socketstat size: ";tempw ‘debug the tempw datasize If Tempw >0Then' if there is something received
Wresult2 =Tcpread(idy, Incomingtcp) ‘read the data Print incomingtcp ‘print the datafordebug End if
loopuntil tempw =0 ‘end the loopon zero bytes
print “end of loop” ‘debugforloopend
incrcounter
if tempw =0andcounter>50then print"reconnect......................................................." counter=0 Socketdisconnect Idy ‘close the socket
Idy =Getsocket(idy , Sock_stream , 1002 , 0)'reopen the socket
Bresult =Socketconnect(idy , ser_digit1.ser_digit2.ser_digit3.ser_digit4 , remoteport , 1)'reconnect to the server Waitms1'0 end if
That actually works, but is not the way I want to leave it. It clears received data without a way to first do something with it.
So I tried something else:
Code:
Tempw =Socketstat(idy , Sel_recv)' get received bytes print"socketstat size: ";tempw ‘debug the tempw datasize If Tempw >0Then' if there is something received Do
Wresult2 =Tcpread(idy, Incomingtcp) ‘read the data Print incomingtcp ‘print the datafordebug End if
Tempw =Socketstat(idy , Sel_recv)' get received bytes print"socketstat size: ";tempw ‘debug the tempw datasize
Loopuntil tempw =0
But that give me the same result.
If I just loop without breaking the loop I get all the data that is send. But than the tcpread will hang on data not being send (waiting for the CR and LF)
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum