Created
March 24, 2013 21:59
-
-
Save gchiu/5233739 to your computer and use it in GitHub Desktop.
Basic tcp port testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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