Question to PB command SendNetworkData

Just starting out? Need help? Post your questions and find answers here.
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Question to PB command SendNetworkData

Post 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
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Question to PB command SendNetworkData

Post 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
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Re: Question to PB command SendNetworkData

Post 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
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
Post Reply