Recently found that frequently I need a tcp server in newlisp to serve simple data requests.
But net-select etc. is a low-level stuff which needs many workarounds in a real usage.
So, once I'v decide to made a such one. Here is it:
//http://en.feautec.pp.ru/store/libs/doc/net-do.lsp.html
... also accessible via "Index: EnFeutec" on
http://www.newlisp.org/modules/
All newlispdoc documented modules can be accessed directly or indirectly from here.
Wow! Cool!
BTW, you can set EnFeautec link directly to the module index:
//http://en.feautec.pp.ru/store/libs/doc/index.html
A usage example:
; use "nc host 8080" to connect, ? to request connections and x to shutdown server
(define (net-do-test)
(net-do 8080 nil 1000
; accept
(fn(conn)
(println "accept: " conn)
(net-send conn "hello!n"))
; receive
(fn(conn , (buf ""))
(println "receive: "conn)
(net-receive conn 'buf 1000)
(if
(starts-with buf "?")
(net-send conn (string net-do:lconn))
(starts-with buf "x")
(set 'net-do:exit-cond true))
(net-send conn "bye!n")
(net-do:close conn))
; cleanout
(fn(conn) (println "closed: " conn))
; cycle
nil
; idle
(fn()(println "idle: " net-do:lconn))))
The timeout is moved from (sleep) to (select), Now in micro-seconds.
Nice!.. a tcp broker at hand ;-)
Version 1.2
Some improvements,code cleanups and fixes.
I always wondered if it would not be nice to dump all the current net- functions
in more reduced functions with more options... But building this is ofcourse a
very nice option ;-)
My ideal IO broker would support "any" IO interface in newlisp..(hint hint..) ;-)