Created
April 11, 2018 00:57
-
-
Save gchiu/4dce1551945cb1c654679bbf1eebb429 to your computer and use it in GitHub Desktop.
simple UDP server
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 [ | |
date: 11-April-2018 | |
title: "simple udp server" | |
] | |
attempt [close listen] | |
print "opening server on port 9000" | |
listen: open udp://: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 [ | |
connect read accept [ | |
print "accepted connection" | |
client: first evt/port | |
client/awake: :awake | |
read client | |
] | |
] | |
] | |
read listen | |
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