[Gambas-user] Trouble writing to Accepted Socket stream

T Lee Davidson t.lee.davidson at gmail.com
Sat Mar 30 09:20:59 CET 2019


I saw you used Flush and so tried it myself thinking perhaps a Socket stream is buffered. Apparently not, since it made no 
difference.

MyConn.Close after Write #MyConn does work now though; when before I got a, "Connection was reset" in the browser. Perhaps I did 
not have the response string built properly according to protocol at that particular time.

The browser is happy with the code I am now using in the Socket_Read event handler. But, what I still don't get, is why the 
Socket_Write event is not triggered, even after the Socket is fully read, until after a Write attempt is made.

[code]
Public Sub Socket_Read()

   For Each sLine As String In MyConn.Lines
     Print sLine
   Next
   Print "Read from socket."

   Wait 0.1 'Socket not ready for writing here.
   Print "Writing to socket."
   Write #MyConn, sResponse, Len(sResponse)
   Wait 0.1  'Socket ready for writing here.
   MyConn.Close

End
[/code]

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

It also does not close the stream.


___
Lee


On 3/29/19 9:25 PM, Cedron Dawg wrote:
> 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.


More information about the User mailing list