[REBOL] Re: REBOL MUD server -- a few easy questions
From: maarten:vrijheid at: 9-Nov-2003 10:27
Here is a (non-tested) sample:
Portz: copy []
Server-port: open/no-wait tcp://:9090
Insert portz server-port
Forever
[
;Use wait/all as all our ports are in one block
current: wait/all portz
;If it's the server accept and add to the list
either server-port = current
[
append portz current
]
;it's data from a client
[
;get the data
data: copy current
;if the data is none then the connection has closed
either none? Data
[
;port closed, remove it from our block
remove find portz current
]
[
;broadcast data, skip the server port
foreach port at portz 2
[
insert port data
]
]
]
]
Note that the port is opend in no-wait, meaning something like "This is
a message" will be broadcasted as it is received, like "This i" "s a me"
ssage
for example. You can add buffering and line termination to this
if you want to. Left as an exercise for the reader ;-)
--Maarten