From: Willy
Subject: beginner question about make-fd-stream
Date: 
Message-ID: <94059dac.0306130023.2ab39eef@posting.google.com>
Hi,

I am a very beginner of lisp and I wrote a small function to read a
tcp data from a stream.

here is the function
================

(defun getyahoo ()
  (let ((stream (sys:make-fd-stream
		 (ext:connect-to-inet-socket "www.yahoo.com" 80)
		 :output t :input t :buffering :full)))
    (format stream "~A~2%" "GET / HTTP/1.0")
    (read-line stream)))

============

I thought the function should at least return the first line of the
reply from the remote site, but it doesn't. The whole lisp seems just
want for something and I need to break it (Ctrl-C) to get the prompt.
Can anyone please help?

Thanks,
Willie

From: Dave Pearson
Subject: Re: beginner question about make-fd-stream
Date: 
Message-ID: <slrnbej69l.3d2.davep.news@hagbard.davep.org>
* Willy <··········@yahoo.com>:

> here is the function
> ================
> 
> (defun getyahoo ()
>   (let ((stream (sys:make-fd-stream
> 		 (ext:connect-to-inet-socket "www.yahoo.com" 80)
> 		 :output t :input t :buffering :full)))
>     (format stream "~A~2%" "GET / HTTP/1.0")
>     (read-line stream)))
> 
> ============
> 
> I thought the function should at least return the first line of the reply
> from the remote site, but it doesn't. The whole lisp seems just want for
> something and I need to break it (Ctrl-C) to get the prompt. Can anyone
> please help?

A quick glance at the above suggests to me that your problem is with your
request, not with the read-line or anything else. Don't you need to end each
line with #\Return and #\NewLine? Also, you should probably place a call to
`FINISH-OUTPUT' after the call to `FORMAT'.

How about something like (not tested):

-- cut here ----------------------------------------------------------------
(defun send-http-line (stream &optional (text ""))
  (format stream "~A~C~C" text #\Return #\NewLine)
  (finish-output stream))

(defun getyahoo ()
  (let ((stream (sys:make-fd-stream
		 (ext:connect-to-inet-socket "www.yahoo.com" 80)
		 :output t :input t :buffering :full)))
    (send-http-line stream "GET / HTTP/1.0")
    (send-http-line stream)
    (read-line stream)))
-- cut here ----------------------------------------------------------------

-- 
Dave Pearson
http://www.davep.org/lisp/
From: Willy
Subject: Re: beginner question about make-fd-stream
Date: 
Message-ID: <94059dac.0306152230.3feec1ea@posting.google.com>
Hi mario and Dave,

I have tried both methods both of you suggested. But still not
working. The lisp is just waiting for something to happen. I am using
CMUCL 18e on Linux 2.4.18

I captured the network packet and confirmed that yahoo does send the
reply to my computer but I just can't read it back using (read-line).
If I change to use (read-n-bytes), which runs ok.

I wonder what is the different between (read-n-bytes) and (read-line)
or the stream created by the (make-fd-stream) compare to normal file
stream.


Thanks.
Willie



Dave Pearson <··········@davep.org> wrote in message news:<·························@hagbard.davep.org>...
> * Willy <··········@yahoo.com>:
> 
> > here is the function
> > ================
> > 
> > (defun getyahoo ()
> >   (let ((stream (sys:make-fd-stream
> > 		 (ext:connect-to-inet-socket "www.yahoo.com" 80)
> > 		 :output t :input t :buffering :full)))
> >     (format stream "~A~2%" "GET / HTTP/1.0")
> >     (read-line stream)))
> > 
> > ============
> > 
> > I thought the function should at least return the first line of the reply
> > from the remote site, but it doesn't. The whole lisp seems just want for
> > something and I need to break it (Ctrl-C) to get the prompt. Can anyone
> > please help?
> 
> A quick glance at the above suggests to me that your problem is with your
> request, not with the read-line or anything else. Don't you need to end each
> line with #\Return and #\NewLine? Also, you should probably place a call to
> `FINISH-OUTPUT' after the call to `FORMAT'.
> 
> How about something like (not tested):
> 
> -- cut here ----------------------------------------------------------------
> (defun send-http-line (stream &optional (text ""))
>   (format stream "~A~C~C" text #\Return #\NewLine)
>   (finish-output stream))
> 
> (defun getyahoo ()
>   (let ((stream (sys:make-fd-stream
> 		 (ext:connect-to-inet-socket "www.yahoo.com" 80)
> 		 :output t :input t :buffering :full)))
>     (send-http-line stream "GET / HTTP/1.0")
>     (send-http-line stream)
>     (read-line stream)))
> -- cut here ----------------------------------------------------------------
From: Willy
Subject: Re: beginner question about make-fd-stream
Date: 
Message-ID: <94059dac.0306172255.44a765c2@posting.google.com>
Hi Dave and Mario,

I am sorry that it was my mistake when I made changes my program.
Actually both of your correction is right. First, I need to set the
buffering mode to :none and as well as I need to add "~A~C~C~C~C" in
the (format) line. Now my program works. Thank you very much!!

Cheers,
Willie

··········@yahoo.com (Willy) wrote in message news:<····························@posting.google.com>...
> Hi mario and Dave,
> 
> I have tried both methods both of you suggested. But still not
> working. The lisp is just waiting for something to happen. I am using
> CMUCL 18e on Linux 2.4.18
> 
> I captured the network packet and confirmed that yahoo does send the
> reply to my computer but I just can't read it back using (read-line).
> If I change to use (read-n-bytes), which runs ok.
> 
> I wonder what is the different between (read-n-bytes) and (read-line)
> or the stream created by the (make-fd-stream) compare to normal file
> stream.
> 
> 
> Thanks.
> Willie
> 
> 
> 
> Dave Pearson <··········@davep.org> wrote in message news:<·························@hagbard.davep.org>...
> > * Willy <··········@yahoo.com>:
> > 
> > > here is the function
> > > ================
> > > 
> > > (defun getyahoo ()
> > >   (let ((stream (sys:make-fd-stream
> > > 		 (ext:connect-to-inet-socket "www.yahoo.com" 80)
> > > 		 :output t :input t :buffering :full)))
> > >     (format stream "~A~2%" "GET / HTTP/1.0")
> > >     (read-line stream)))
> > > 
> > > ============
> > > 
> > > I thought the function should at least return the first line of the reply
> > > from the remote site, but it doesn't. The whole lisp seems just want for
> > > something and I need to break it (Ctrl-C) to get the prompt. Can anyone
> > > please help?
> > 
> > A quick glance at the above suggests to me that your problem is with your
> > request, not with the read-line or anything else. Don't you need to end each
> > line with #\Return and #\NewLine? Also, you should probably place a call to
> > `FINISH-OUTPUT' after the call to `FORMAT'.
> > 
> > How about something like (not tested):
> > 
> > -- cut here ----------------------------------------------------------------
> > (defun send-http-line (stream &optional (text ""))
> >   (format stream "~A~C~C" text #\Return #\NewLine)
> >   (finish-output stream))
> > 
> > (defun getyahoo ()
> >   (let ((stream (sys:make-fd-stream
> > 		 (ext:connect-to-inet-socket "www.yahoo.com" 80)
> > 		 :output t :input t :buffering :full)))
> >     (send-http-line stream "GET / HTTP/1.0")
> >     (send-http-line stream)
> >     (read-line stream)))
> > -- cut here ----------------------------------------------------------------
From: Mario S. Mommer
Subject: Re: beginner question about make-fd-stream
Date: 
Message-ID: <fz1xxytlxb.fsf@cupid.igpm.rwth-aachen.de>
··········@yahoo.com (Willy) writes:
> Hi,
> 
> I am a very beginner of lisp and I wrote a small function to read a
> tcp data from a stream.
> 
> here is the function
> ================
> 
> (defun getyahoo ()
>   (let ((stream (sys:make-fd-stream
> 		 (ext:connect-to-inet-socket "www.yahoo.com" 80)
> 		 :output t :input t :buffering :full)))
                                               ^^^^^
Try :none here, for starters. Does it help?

>     (format stream "~A~2%" "GET / HTTP/1.0")
>     (read-line stream)))
> 
> ============

Regards,
        Mario.