Page 1 of 1

TCP/IP server suite

Posted: Wed Mar 12, 2008 12:43 pm
by Dmi
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

Posted: Wed Mar 12, 2008 1:22 pm
by Lutz
... also accessible via "Index: EnFeutec" on

http://www.newlisp.org/modules/

All newlispdoc documented modules can be accessed directly or indirectly from here.

Posted: Wed Mar 12, 2008 2:04 pm
by Dmi
Wow! Cool!

BTW, you can set EnFeautec link directly to the module index:

http://en.feautec.pp.ru/store/libs/doc/index.html

example

Posted: Wed Mar 12, 2008 2:09 pm
by Dmi
A usage example:

Code: Select all

     ; 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))))

update

Posted: Wed Mar 12, 2008 4:01 pm
by Dmi
The timeout is moved from (sleep) to (select), Now in micro-seconds.

Posted: Wed Mar 12, 2008 7:15 pm
by newdep
Nice!.. a tcp broker at hand ;-)

Posted: Thu Mar 13, 2008 10:32 am
by Dmi
Version 1.2
Some improvements,code cleanups and fixes.

Posted: Thu Mar 13, 2008 6:44 pm
by newdep
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..) ;-)