(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