Simple send-to-all TCP server in LUA
July 25th, 2008I did a lot of boring stuff yesterday so in the evening I felt I deserve a small treat. I decided to finally get more familiar with 2 of the C* words - coroutines and closures . I know partially what they are and used them here and there, but haven’t really gotten deeper in. Lua can do these without blinking so I decided to make a simple tcp server with it and see if I can use them on the way there.

The code works but it’s not in any final state yet. The server accepts any number of TCP connections which it then keeps open and when it recieves a text from any of them it sends that text to all clients. If I would add nicknames you would have a simple chat server (but I made enough of those already). I also made quick GUI client for testing in REBOL, code here and a quick stress test script in REBOL too ( code here )
I did use a closure in a rather cool way (I think), and I implemented coroutines but in the current code they have no meaning to be there. They will get needed if I will extend the thing into something more interesting. I will write more about some interesting parts of the code next time.

