TCP/IP server suite

Notices and updates
Locked
Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

TCP/IP server suite

Post 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
WBR, Dmi

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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.

Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post 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
WBR, Dmi

Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

example

Post 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))))
WBR, Dmi

Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

update

Post by Dmi »

The timeout is moved from (sleep) to (select), Now in micro-seconds.
WBR, Dmi

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Nice!.. a tcp broker at hand ;-)
-- (define? (Cornflakes))

Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

Version 1.2
Some improvements,code cleanups and fixes.
WBR, Dmi

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post 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..) ;-)
-- (define? (Cornflakes))

Locked