From: Christophe Turle
Subject: trivial sockets
Date: 
Message-ID: <417c02a8$0$24449$636a15ce@news.free.fr>
"Trivial sockets" Announced by dan barlow :

(with-open-stream (s (trivial-sockets:open-stream "www.google.com" 80))
  (format s "HEAD / HTTP/1.0~%Host: www.google.com~%~%")
  (force-output s)
  (read-line s))

If the goal is to go the extreme, suggestions :

(trivial-sockets:with-open-stream (s "www.google.com" 80)
  (format s "HEAD / HTTP/1.0~%Host: www.google.com~%~%")
  (force-output s)
  (read-line s))

and why not :

(trivial-sockets:with-open-www-stream (s "www.google.com") ; port defaults 
to 80
  (format s "HEAD / HTTP/1.0~%Host: www.google.com~%~%")
  (force-output s)
  (read-line s))


___________________________________________________________
Christophe Turle.
sava preview http://perso.wanadoo.fr/turle/lisp/sava.html
(format nil ···@~a.~a" 'c.turle 'wanadoo 'fr) 

From: Christophe Rhodes
Subject: Re: trivial sockets
Date: 
Message-ID: <sqk6tfnbwf.fsf@cam.ac.uk>
"Christophe Turle" <······@nospam.com> writes:

> "Trivial sockets" Announced by dan barlow :

I'm not speaking for Dan, obviously.

> If the goal is to go the extreme, suggestions :
>
> (trivial-sockets:with-open-stream (s "www.google.com" 80)

Wildly incompatible shadowing of a Common Lisp symbol, leading to
confusion when someone uses it in their package.

> and why not :
>
> (trivial-sockets:with-open-www-stream (s "www.google.com") ; port defaults to 80

Hideous complication of the interface, increased maintenance costs, no
noticeable improvement in expressive power.

Christophe
From: Christophe Turle
Subject: Re: trivial sockets
Date: 
Message-ID: <417c0d3d$0$24438$636a15ce@news.free.fr>
"Christophe Rhodes" <·····@cam.ac.uk> a �crit dans le message de news: 
··············@cam.ac.uk...
> "Christophe Turle" <······@nospam.com> writes:
>
>> "Trivial sockets" Announced by dan barlow :
>
> I'm not speaking for Dan, obviously.
>
>> If the goal is to go the extreme, suggestions :
>>
>> (trivial-sockets:with-open-stream (s "www.google.com" 80)
>
> Wildly incompatible shadowing of a Common Lisp symbol, leading to
> confusion when someone uses it in their package.

oops ! it was :

(trivial-sockets:with-inet-stream (s "www.google.com" 80)
  ... )

>> and why not :
>>
>> (trivial-sockets:with-open-www-stream (s "www.google.com") ; port 
>> defaults to 80
>
> Hideous complication of the interface, increased maintenance costs,

And there :

(trivial-sockets:with-www-stream (s "www.google.com")
  ... )

> no noticeable improvement in expressive power.

I think the 'port number' defaulting worth the new function name.

And i think it's up to Dan to give it. Not that it's hard, but it's that 
sort of things which needs 'standardization'. Else lots of people will write 
their with-www-stream wrapper.


-- 
___________________________________________________________
Christophe Turle.
sava preview http://perso.wanadoo.fr/turle/lisp/sava.html
(format nil ···@~a.~a" 'c.turle 'wanadoo 'fr) 
From: Daniel Barlow
Subject: Re: trivial sockets
Date: 
Message-ID: <87hdoj3evp.fsf@noetbook.telent.net>
"Christophe Turle" <······@nospam.com> writes:

> "Trivial sockets" Announced by dan barlow :

For anyone who hasn't seen my previous posts on Planet Lisp or
somewhere, it may not be clear exactly what's in TRIVIAL-SOCKETS
already and what's Christophe's suggestion for improvement.  So,
background:

TRIVIAL-SOCKETS is a socket interface for "undemanding network
applications".  In its current incarnation, it exports one function
OPEN-STREAM which opens a client socket to some Internet-family stream
(e.g. TCP-based) server, such as HTTP, SMTP, Finger, Telnet or
whatever.  It accepts hostnames or IP addresses and signals a
documented kind of error if something goes wrong.  More information by
following pointers from http://www.cliki.net/trivial-sockets

> If the goal is to go the extreme, suggestions :
>
> (trivial-sockets:with-open-stream (s "www.google.com" 80)
> (trivial-sockets:with-open-www-stream (s "www.google.com") ; port defaults 
> to 80

:; grep tcp /etc/services | wc -l
254

If with-open-www-stream, why not with-open-smtp-stream,
with-open-pop-stream or even with-open-gnutella-rtr-stream?
Seriously, I would expect from a protocol-specific function name 
that it did some protocol-specific parsing instead of just opening a
plain tcp connection.

(For http streams, for example, the obvious "value add" would be to
accept and parse an input url instead of just accepting hostname and
port)

On the other hand, it _would_ be good if trivial-sockets could look
services up by name (getservbyname() or /etc/services or local
equivalent) instead of requiring the user to know the number, so I'll
add that if I can find a way to look them up in sufficiently many Lisp
implementations to make it worthwhile.

Thanks for your suggestions.


-dan

-- 
"please make sure that the person is your friend before you confirm"
From: FormerPerlHacker
Subject: Re: trivial sockets
Date: 
Message-ID: <slrncnr4jg.5re.spambait@phoenix.clouddancer.com>
On Sun, 24 Oct 2004 23:55:38 +0100, <···@telent.net> wrote:
>
> TRIVIAL-SOCKETS is a socket interface for "undemanding network
> applications".  In its current incarnation, it exports one function
> OPEN-STREAM which opens a client socket to some Internet-family stream
> (e.g. TCP-based) server, such as HTTP, SMTP, Finger, Telnet or
> whatever.  It accepts hostnames or IP addresses and signals a
> documented kind of error if something goes wrong.  More information by
> following pointers from http://www.cliki.net/trivial-sockets
>

I wish that I had seen this about 5 years ago.  At that time, I chose
to go into perl to solve HTTP parsing into an SQL database, with
subsequent data analysis and prediction.  Now I'm repeating the effort
in lisp, so I'm happy to see this.  The speed of lisp, and Kozas tools
are far, far better for my needs.

But bringing in new packages in lisp, and then creating stand-alone
executables is still new to me.  So following a link that just dumps
me into a CVS without a 'basic dummy' prompt to download 'cmucl.lisp'
leaves me lost.  A sample program to take "I feel lucky' from goggle
for a simple string would help immensely.


> If with-open-www-stream, why not with-open-smtp-stream,
> with-open-pop-stream or even with-open-gnutella-rtr-stream?
> Seriously, I would expect from a protocol-specific function name 
> that it did some protocol-specific parsing instead of just opening a
> plain tcp connection.

All of which would be more than 'trivial'.


-- 
Brownian motion is correctly colored.
From: Daniel Barlow
Subject: Re: trivial sockets
Date: 
Message-ID: <87mzy7zmq4.fsf@noetbook.telent.net>
FormerPerlHacker <··················@CloudDancer.com> writes:

> I wish that I had seen this about 5 years ago.  At that time, I chose

I hadn't written it five years ago, so please don't feel that you
wasted the intervening half decade or anything ;-)

[...]
> But bringing in new packages in lisp, and then creating stand-alone
> executables is still new to me.  So following a link that just dumps
> me into a CVS without a 'basic dummy' prompt to download 'cmucl.lisp'
> leaves me lost.  A sample program to take "I feel lucky' from goggle
> for a simple string would help immensely.

Well, OK.  The first point is that it's asdf-installable now, which
should make it easier to get it started if you have a lisp
implementation with asdf-install bundled.  In SBCL, for example, just
do

   * (require 'asdf-install)
   * (asdf-install:install 'trivial-sockets)

and respond appropriately to the ensuing messages complaining that
you've never signed my PGP key (i.e. tell it that you want to ignore
the possibility that my key may not be mine, and that you trust me to
write Lisp code) and it will download and compile it.  Next time you
start SBCL you need only (require 'trivial-sockets) and there it is.

(Users of asdf-install in other lisps are welcome to chip in at this
point.  I think openmcl has a fairly simple setup, and cmucl is using
asdf-install for its own patches in 19a, but I'm not aware if you need
to download stuff first to get that to work)

Once you have trivial-sockets loaded, write your function to talk to
google.  The one I knocked up for illustrative purposes looks like
this:

(defun lucky (string)
  (let ((string (substitute #\+ #\Space string)))
    (with-open-stream (s (trivial-sockets:open-stream "www.google.com" 80))
      (format s "GET /search?q=~A&btnI=lucky HTTP/1.0
Host: www.google.com~%~%" string)
      (force-output s) 
       (loop 
	(let ((r (read-line s nil nil)))
	  (unless r (return nil))
	  (when (> (mismatch r "Location: ") 9)
	    ;; this business with position is supposed to work regardless
	    ;; of whether the implementation's READ-LINE leaves the \r on
	    (return (subseq r 10 (position (code-char 13) r :from-end t)))))))))

and indeed,  evaluating

(lucky "trivial sockets") 
=> "http://cvs.telent.net/cgi-bin/viewcvs.cgi/trivial-sockets/"

I don't claim this is a full implementation of HTTP (it's not), or
that it's efficient (but if latency to google is ~30ms anyway, who
cares?), or that it's portable lisp code (there's some line-ending
handwaving going on), but it appears to do the job.  

Turning it into a standalone program will require recourse to your
implementation's documentation.  My suggestion is that you do not
bother to try: instead of programming by writing commands and
connecting them together at the shell prompt, program by constructing
functions and nesting them together at the repl.  Then you can even
have one "program" return actual objects to the next, instead of
having to serialise everything down to a text stream then have the
following program parse it again.


-dan

-- 
"please make sure that the person is your friend before you confirm"
From: Raymond Toy
Subject: Re: trivial sockets
Date: 
Message-ID: <4180F9A2.4060704@rtp.ericsson.se>
Daniel Barlow wrote:
> 
> (Users of asdf-install in other lisps are welcome to chip in at this
> point.  I think openmcl has a fairly simple setup, and cmucl is using
> asdf-install for its own patches in 19a, but I'm not aware if you need
> to download stuff first to get that to work)

Since you asked, the asdf-install support didn't make it into cmucl 19a. 
  If you want that, you have to grab cmucl-19a-patch-000.tar.gz from

ftp://ftp.common-lisp.net/project/cmucl/release/19a/patches

Once you have that installed somewhere, you can load it up in your 
.cmucl-init.lisp, and then (require 'asdf) and asdf-install will work.

If not, please send a note to the cmucl-imp mailing list.

Ray
From: FormerPerlHacker
Subject: Re: trivial sockets
Date: 
Message-ID: <slrncnrenj.5re.spambait@phoenix.clouddancer.com>
On Sun, 24 Oct 2004 23:55:38 +0100, <···@telent.net> wrote:
> "Christophe Turle" <······@nospam.com> writes:
>
>> If the goal is to go the extreme, suggestions :
>>
>> (trivial-sockets:with-open-stream (s "www.google.com" 80)
>> (trivial-sockets:with-open-www-stream (s "www.google.com") ; port defaults 
>> to 80
>
>:; grep tcp /etc/services | wc -l
> 254
>
> If with-open-www-stream, why not with-open-smtp-stream,
> with-open-pop-stream or even with-open-gnutella-rtr-stream?
> Seriously, I would expect from a protocol-specific function name 
> that it did some protocol-specific parsing instead of just opening a
> plain tcp connection.


None of which is 'trivial'.  It must be 'successful', less than a week
old and already people want to tinker with it.


-- 
Brownian motion is correctly colored.
From: Daniel Barlow
Subject: ANN: trivial-sockets 0.1 asdf-installable
Date: 
Message-ID: <87y8htymt4.fsf_-_@noetbook.telent.net>
--=-=-=


TRIVIAL-SOCKETS is a socket interface for "undemanding network
applications".  In its current incarnation, it exports one function
OPEN-STREAM which opens a client socket to some Internet-family stream
(e.g. TCP-based) server, such as HTTP, SMTP, Finger, Telnet or
whatever.  It accepts hostnames or IP addresses and signals a
documented kind of error if something goes wrong.  

(with-open-stream (s (trivial-sockets:open-stream "www.google.com" 80)) 
  (format s "HEAD / HTTP/1.0~%Host: www.google.com~%~%") 
  (force-output s) 
  (loop 
    (let ((l (read-line s nil nil))) 
      (unless l (return)) 
      (princ l) (terpri))))

More information by following pointers from

  http://www.cliki.net/trivial-sockets

In version 0.1, TRIVIAL-SOCKETS can be installed automatically with
asdf-install and supports (in alphabetical order) Allegro CL, CLISP,
CMUCL, OpenMCL, and SBCL

  http://www.cliki.net/asdf-install



>
>> If the goal is to go the extreme, suggestions :
>>
>> (trivial-sockets:with-open-stream (s "www.google.com" 80)
>> (trivial-sockets:with-open-www-stream (s "www.google.com") ; port defaults 
>> to 80
>
> :; grep tcp /etc/services | wc -l
> 254
>
> If with-open-www-stream, why not with-open-smtp-stream,
> with-open-pop-stream or even with-open-gnutella-rtr-stream?
> Seriously, I would expect from a protocol-specific function name 
> that it did some protocol-specific parsing instead of just opening a
> plain tcp connection.
>
> (For http streams, for example, the obvious "value add" would be to
> accept and parse an input url instead of just accepting hostname and
> port)
>
> On the other hand, it _would_ be good if trivial-sockets could look
> services up by name (getservbyname() or /etc/services or local
> equivalent) instead of requiring the user to know the number, so I'll
> add that if I can find a way to look them up in sufficiently many Lisp
> implementations to make it worthwhile.
>
> Thanks for your suggestions.
>
>
> -dan
>
> -- 
> "please make sure that the person is your friend before you confirm"


-- 
"please make sure that the person is your friend before you confirm"

--=-=-=
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQBBfvkMHDK5ZnWQiRMRAiTJAJ4g9c+6lJ92Gmwoe/WN8WsokWzYGwCaAz9z
Pa7ILp13kcTUsFyHGGy+JRU=
=Eseo
-----END PGP SIGNATURE-----
--=-=-=--
From: Peter Seibel
Subject: Re: ANN: trivial-sockets 0.1 asdf-installable
Date: 
Message-ID: <m3u0shylq6.fsf@javamonkey.com>
Daniel Barlow <···@telent.net> writes:

> TRIVIAL-SOCKETS is a socket interface for "undemanding network
> applications".  In its current incarnation, it exports one function
> OPEN-STREAM which opens a client socket to some Internet-family stream
> (e.g. TCP-based) server, such as HTTP, SMTP, Finger, Telnet or
> whatever.  It accepts hostnames or IP addresses and signals a
> documented kind of error if something goes wrong.  
>
> (with-open-stream (s (trivial-sockets:open-stream "www.google.com" 80)) 
>   (format s "HEAD / HTTP/1.0~%Host: www.google.com~%~%") 
>   (force-output s) 
>   (loop 
>     (let ((l (read-line s nil nil))) 
>       (unless l (return)) 
>       (princ l) (terpri))))
>
> More information by following pointers from
>
>   http://www.cliki.net/trivial-sockets
>
> In version 0.1, TRIVIAL-SOCKETS can be installed automatically with
> asdf-install and supports (in alphabetical order) Allegro CL, CLISP,
> CMUCL, OpenMCL, and SBCL
>
>   http://www.cliki.net/asdf-install


Since you seem to be going great guns on this, any thought of
providing equally trivial support for the server-side sockets? E.g.:

  (with-open-stream (ss (trivial-sockets::open-server-socket 80))
    (loop
      (with-open-stream (s (trivial-sockets::accept ss))
        (do-http s))))

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: ···@telent.net
Subject: Re: ANN: trivial-sockets 0.1 asdf-installable
Date: 
Message-ID: <1098873594.772804.38380@f14g2000cwb.googlegroups.com>
Peter Seibel wrote:
> Since you seem to be going great guns on this, any thought of
> providing equally trivial support for the server-side sockets? E.g.:

Yes, indeed.  It's going to be a bit less trivial in that IWBNI it were
thread-tolerant, usable with callback event loops, etc.  Coming soon,
probably.


-dan
From: Peter Seibel
Subject: Re: ANN: trivial-sockets 0.1 asdf-installable
Date: 
Message-ID: <m38y9syusm.fsf@javamonkey.com>
···@telent.net writes:

> Peter Seibel wrote:
>> Since you seem to be going great guns on this, any thought of
>> providing equally trivial support for the server-side sockets? E.g.:
>
> Yes, indeed. It's going to be a bit less trivial in that IWBNI it
> were thread-tolerant, usable with callback event loops, etc. Coming
> soon, probably.

Cool!

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp