Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

socketstat issue

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> EASY TCP/IP
View previous topic :: View next topic  
Author Message
wielklem

Bascom Member



Joined: 20 Nov 2008
Posts: 47
Location: the Netherlands

blank.gif
PostPosted: Mon May 30, 2022 7:34 pm    Post subject: socketstat issue Reply with quote

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 data size
               If Tempw > 0 Then                                         ' if there is something received

                Wresult2 = Tcpread(idy, Incomingtcp)    ‘read the data
                Print incomingtcp                       ‘print the data for debug
        End if

loop until tempw = 0                            ‘end the loop on zero bytes
        printend of loop”                             ‘debug for loop end



 


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 data size
               If Tempw > 0 Then                                         ' if there is something received

                Wresult2 = Tcpread(idy, Incomingtcp)    ‘read the data
                Print incomingtcp                       ‘print the data for debug
        End if

loop until tempw = 0                            ‘end the loop on zero bytes
        printend of loop”                             ‘debug for loop end

        incr counter


      if tempw = 0 and counter > 50 then
      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
      Waitms 1'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 data size
               If Tempw > 0 Then                                         ' if there is something received
        Do

                Wresult2 = Tcpread(idy, Incomingtcp)    ‘read the data
                Print incomingtcp                       ‘print the data for debug
        End if
        Tempw = Socketstat(idy , Sel_recv)                       ' get received bytes
               print "socketstat size: ";tempw                  ‘debug the tempw data size

        Loop until 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)

Any suggestions?
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> EASY TCP/IP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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