[Gambas-user] Trouble writing to Accepted Socket stream

Jussi Lahtinen jussi.lahtinen at gmail.com
Sat Mar 30 01:38:57 CET 2019


MySock_Ready, instead of Socket_Ready?
Why there is out commented write in read event?


Jussi

On Sat, Mar 30, 2019 at 12:26 AM T Lee Davidson <t.lee.davidson at gmail.com>
wrote:

> I'm using ServerSocket to listen for connections on localhost:8080. When I
> make a request to that URI with my browser, it just
> hangs, "Waiting for localhost..."
>
> In the ServerSocket.Connection event, I accept the connection which
> creates a Socket object to manage that connection. The issue
> seems to be that the accepted socket stream never becomes ready for
> writing unless I actually try to write to it. If I then
> write to the stream in the Socket.Write event (because that's when it is
> supposed to be ready for writing), I get a nearly
> endless loop that doesn't give up until around 23000 iterations.
>
> [code]
> ' Gambas module file
>
> Private hServerSocket As ServerSocket
> Private MyConn As Socket
> Private crlf As String = Chr(13) & Chr(10)
> Private sResponse As String = "HTTP/1.1 200 OK" & crlf & crlf & "Hello
> world!"
> Private Count As Integer
>
> Public Sub Main()
>
>    hServerSocket = New ServerSocket As "MySock"
>    hServerSocket.Type = Net.Internet
>    hServerSocket.Port = 8080
>    hServerSocket.Listen
>
> End
>
> Public Sub MySock_Connection(RemoteHostIP As String)
>
>    MyConn = hServerSocket.Accept()
>
> End
>
> Public Sub Socket_Ready()
>
>    Print "Socket READY."
>
> End
>
> Public Sub Socket_Read()
>
>    For Each sLine As String In MyConn.Lines
>      Print sLine
>    Next
>
>    ' Print "Writing to stream."
>    ' Write #MyConn, sResponse, Len(sResponse) 'Socket not ready for
> writing until here.
>
> End
>
> Public Sub Socket_Write()
>
>    Print "Socket ready for writing."
>    ' Inc Count
>    ' Print Count
>    ' Write #MyConn, sResponse, Len(sResponse) 'Nearly endless loop created
> here.
>
> End
> [/code]
>
> What am I doing wrong?
>
>
> ___
> Lee
>
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20190330/7e42aee3/attachment-0001.html>


More information about the User mailing list