Skip to content

Instantly share code, notes, and snippets.

@gchiu
Created April 11, 2018 00:57
Show Gist options
  • Save gchiu/4dce1551945cb1c654679bbf1eebb429 to your computer and use it in GitHub Desktop.
Save gchiu/4dce1551945cb1c654679bbf1eebb429 to your computer and use it in GitHub Desktop.
simple UDP server
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