Advertisement
Starkkz

BlitzMax non-blocking TCP connection

Mar 31st, 2013
3,242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function ConnectThread:Object(data:Object)
  2.     stream = OpenTCPStream("www.unrealsoftware.de", 80)
  3.     If Not stream Then
  4.         Print "Failed to connect ("+last_ms+")"
  5.         End
  6.     End If
  7.    
  8.     If TCPStreamConnected(stream) Then
  9.         Print "CONNECTED!! ("+last_ms+")"
  10.         End
  11.     Else
  12.         Print "Disconnected ("+last_ms+")"
  13.         End
  14.     End If
  15. End Function
  16.  
  17. Function Connect()
  18.     CreateThread ConnectThread, Null
  19. End Function
  20.  
  21. Global start_ms = MilliSecs()
  22. Global last_ms
  23. Global stream:TTCPStream
  24.  
  25. Connect()
  26.  
  27. Repeat
  28.     Local current_ms = MilliSecs() - start_ms
  29.  
  30.     If current_ms <> last_ms Then
  31.         last_ms = current_ms
  32.         If stream And TCPStreamConnected(stream) Then
  33.             Print "Proccess complete! app is already connected ("+last_ms+")"
  34.             Print "Waiting for app terminate"
  35.         Else
  36.             Print "Connecting ("+last_ms+")"
  37.         End If
  38.     End If
  39. Forever
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement