[Gambas-user] Trouble writing to Accepted Socket stream
Cedron Dawg
cedron at exede.net
Sat Mar 30 02:25:16 CET 2019
Inserting a "Close" makes your code work on the browser end as well. It also allow a refresh to occur.
Public Sub Socket_Read()
Dim r As String
Print "1 MyConn.Status = "; MyConn.Status
For Each sLine As String In MyConn.Lines
Print sLine
Next
Print "2 MyConn.Status = "; MyConn.Status
r = sResponse & " " & Now()
Print "Writing to stream."
Write #MyConn, r, Len(r) 'Socket not ready for writing until here.
Flush #MyConn
Print "3 MyConn.Status = "; MyConn.Status
Close #MyConn
Print "4 MyConn.Status = "; MyConn.Status
End
I would note that the sample code provided (at the bottom) in
http://gambaswiki.org/wiki/doc/network
Does *not* employ the "Write" event handler.
With the close statement in there, a Telnet session exits immediately with
"Connection closed by foreign host."
We used to use Telnet to test servers being up.
----- Original Message -----
From: "T Lee Davidson" <t.lee.davidson at gmail.com>
To: "user" <user at lists.gambas-basic.org>
Sent: Friday, March 29, 2019 8:10:31 PM
Subject: Re: [Gambas-user] Trouble writing to Accepted Socket stream
The issue is not whether or not I am correctly implementing the HTTP protocol. The issue is that the Socket object isn't
correctly writing to the stream.
The Socket doesn't become ready-to-write until AFTER I actually try to write to it. It's as if a Write attempt triggers the
Socket.Write (ready-to-write) event handler. If I then attempt write to the stream in that handler, because it should be ready
to right, it gets stuck in a self-triggering loop.
BTW, "HTTP/1.1 200 OK" & crlf & crlf & "Hello world!" should be sufficient to satisfy the browser. It works with test servers
coded in Python, Golang, and Rust.
___
Lee
More information about the User
mailing list