Buggy post url cmd - socket stays open

Dave Cragg dcragg at lacscentre.co.uk
Thu Jul 24 11:51:01 EDT 2003


At 8:19 pm -0700 23/7/03, Alain Farmer wrote:
>Hello Scott and y'all,
>
>I have a persistant problem with the "post url" syntax
>of MetaCard 2.5, as I did with 2.4 as well. The client
>is a MetaCard 2.5 stack with the following handler in
>a button :
>
>on mouseUp
>   put "http://www.giguere.uqam.ca/" into myHost
>   put myHost & "XA/MenusXApost.cgi" into myURL
>   if the openSockets is empty then
>     post field 1 to url myURL
>     if the result is not empty
>     then answer the result
>     else answer it
>   else
>     beep
>   end if
>end mouseUp
>
>The CGI program on the server-side is a
>HyperCard-based CGI which performs marvelously. It
>returns the minimum set of HTTP headers required by
>MetaCard. The proof of this is that the first click on
>the above button indeed returns what it is supposed
>to. Btw, I am using Webstar 2.1 on MacOS 8.6 on the
>server-side.
>
>The problem arises after the first click of this
>button. On the second and subsequent clicks of this
>button, the handler beeps, e.g. the openSockets is not
>empty which, IOW, means that the socket remains open
>after the first click. In fact, it (the socket)
>*never* closes, and this inhibits it from doing its
>thing more than once.

>My diagnostic, therefore, is that there is a bug in
>MC's post command whereby the socket that is opened is
>never closed. Please fix this *bug* by making the
>socket close automatically ASAP after the reply is
>received by the MC client. Or give us the new syntax
>we need to *close* the open sockets ourselves.
>
>If you disbelieve my account, then feel free to
>download a copy of my client stack which exhibits this
>problem :

I believe you. But the behavior is intentional. By default, the 
libUrl script doesn't close the socket after completing a request. 
This allows re-use of the same socket which is useful if you are 
making a series of requests to the same server, and is in line with 
the HTTP 1.1 spec. (The socket will eventually get closed by the 
server.)

Is there any reason that you need to check that the openSockets is 
empty? If it's just to prevent someone clicking on the button again 
while the request is being handled, you could disable the button at 
the top of the script and re-enable it after the request has 
completed.

But if you really want to have the socket closed after the post 
competes, then the "proper" way would be to set the httpHeaders as 
follows:

set the httpHeaders to "Connection: close"

If you do this, the server should immediately close the socket after 
completing the post request (assuming the server is HTTP 1.1 
compliant -- I don't know about Webstar 2.1)

Cheers
Dave







More information about the metacard mailing list