a few network procedures for everyone
Posted: Mon May 12, 2003 10:46 pm
since pb was lacking getnetworkstring() commands, i made a few of my own for an application i'm working on. feel free to use them as you please. i made 2 different ones, one that waits for data to be recieved (and times out after 30 seconds of waiting), and the other that assumes data is there & ready to be read
(you may want to de-allocate the buffer memory after use, i don't simply because my app uses it repeatedly, and each time it's re-allocated it frees the old memory)
Aszid
(you may want to de-allocate the buffer memory after use, i don't simply because my app uses it repeatedly, and each time it's re-allocated it frees the old memory)
Code: Select all
Procedure.s WaitNetworkString(conn)
secstamp = Date()
Repeat
winact = WindowEvent()
If winact = #PB_EventGadget
If EventGadgetID() = #Cancel ; this is my cancel button
End
EndIf
EndIf
netact = NetworkClientEvent(conn)
Delay(20)
If Date() > secstamp + 30
netact = 10
EndIf
Until netact <> 0
If netact = 10
MessageRequester("Connection error","Server has timed out",0)
ProcedureReturn ""
Elseif netact = 2
*buffer = AllocateMemory(#1,10240 , 0)
strlen = ReceiveNetworkData(servconn,*buffer,10240)
rdata$ = PeekS(*buffer)
rdata$ = Left(rdata$,strlen)
ProcedureReturn rdata$
EndIf
EndProcedure
Procedure.s GetNetworkString(conn)
*buffer = AllocateMemory(#1, 10240 , 0)
strlen = ReceiveNetworkData(servconn,*buffer,10240)
rdata$ = PeekS(*buffer)
rdata$ = Left(rdata$,strlen)
ProcedureReturn rdata$
EndProcedure