Page 1 of 1

Question to PB command SendNetworkData

Posted: Fri Jul 09, 2010 3:10 pm
by helpy
Hello all,

I have a question to the Result of the PB command SendNetworkData:
The 'Result' is the number of bytes, that was actually sent. If it is not equal to the 'Length' parameter, the receiving buffer of the user is probally full. If nothing could be sent then 'Result' will equal -1.
If I send a block (block header has information about content and block length) and SendNetworkData() returns a vlaue between '0' and 'length'.

Does that mean, that I have to send the whole block again ... or do I only have to send the part of the block, which hast not already been sent?

cu, helpy

Re: Question to PB command SendNetworkData

Posted: Sat Jul 10, 2010 12:57 am
by idle
Yes you keep sending until its done, mostly the error you'll get is from the send buffer being full.

something like this

Code: Select all

#WSAEWOULDBLOCK = 10035
#WSAECONNABORTED = 10053

Procedure Send(Connection.i,*DataBuffer,Size)
  
 Protected delay.i,Tx.i,Result.i,bConnectionDropped.i,timeOut.i,bTimeout.i
 
 Timeout = ElapsedMilliseconds() + 5000
 
 Repeat  
   
   Result = SendNetworkData(Connection ,*DataBuffer+Tx,Size-Tx)
                      
   If Result <> -1 
     Tx = Tx + Result
     delay=0
     timeout = ElapsedMilliseconds() + 5000
   Else 
      err = WSAGetLastError_()  
      If err = #WSAECONNABORTED
        bConnectionDropped = 1
        Break 
      ElseIf err = #WSAEWOULDBLOCK
        delay = 50
      EndIf
      If ElapsedMilliseconds() > timeout  
        btimeout = 1 
        Break 
      EndIf   
   EndIf   
   Delay(delay)   
    
 Until Tx = Size
  
 If bConnectionDropped Or bTimeout  
   ProcedureReturn 0 
 Else   
   ProcedureReturn Tx
 EndIf 
  
EndProcedure

Re: Question to PB command SendNetworkData

Posted: Sat Jul 10, 2010 11:39 am
by helpy
Thank you idle ... now I understand a bit more ;-)

Sometimes it would be helpful, if there would be some more information in the PureBasic help (i.e. SendNetworkData and also ReceiveNetworkData, ...)

cu, helpy