Skip to content

Instantly share code, notes, and snippets.

@gchiu
Created April 10, 2018 18:37
Show Gist options
  • Save gchiu/729400d7c4490659c494f0aed022cb10 to your computer and use it in GitHub Desktop.
Save gchiu/729400d7c4490659c494f0aed022cb10 to your computer and use it in GitHub Desktop.
simple tcp server doesn't work with udp
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