Created
April 10, 2018 18:37
-
-
Save gchiu/729400d7c4490659c494f0aed022cb10 to your computer and use it in GitHub Desktop.
simple tcp server doesn't work with udp
This file contains hidden or 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 [ | |
date: 11-April-2018 | |
title: "simple tcp server" | |
] | |
attempt [close listen] | |
print "opening server on port 9000" | |
listen: open tcp://:9000 | |
awake: function [evt][ | |
print "Client event" | |
dump evt/type | |
port: evt/port | |
switch evt/type [ | |
connect [] | |
read [ | |
print to string! port/data | |
clear port/data | |
read port | |
] | |
close [exit] | |
exit | |
] | |
] | |
listen/awake: function [evt][ | |
print "Listen event" | |
dump evt/type | |
switch evt/type [ | |
accept [ | |
print "accepted connection" | |
client: first evt/port | |
client/awake: :awake | |
read client | |
] | |
] | |
] | |
forever [ | |
if blank? data: wait [listen 10][ | |
print "timed out" | |
] | |
] | |
close listen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment