Skip to content

Instantly share code, notes, and snippets.

@gchiu
Created March 24, 2013 21:59
Show Gist options
  • Save gchiu/5233739 to your computer and use it in GitHub Desktop.
Save gchiu/5233739 to your computer and use it in GitHub Desktop.
Basic tcp port testing
rebol [
]
android-request: {{"params": ["Hello, Android!"], "id":1, "method": "makeToast"}^/}
android-port: make port! tcp://192.168.1.103:4321
android-port/awake: func [event /local tcp-port] [
tcp-port: event/port
print [ "port equality?" equal? tcp-port android-port ]
print ["==TCP-event:" event/type]
switch/default event/type [
read [
; data has arrived
print ["^\read:" length? tcp-port/data]
]
wrote [
print "have a wrote event, so read response from server"
read tcp-port
]
lookup [
; this event should not happen if passed an IP address as in this example
; it would happen though if we had used tcp://rebol.com:4321
print "opening tcp port - should not occur with an IP address"
open tcp-port
]
connect [
; these two are equivalent
; write tcp-port android-request
write android-port android-request
]
][
; returns if receives other events like done, close, error, custom
true
]
]
open android-port
wait [android-port 3]
either android-port/data [
print to string! android-port/data
][ print "no response" ]
close android-port
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment