[Gambas-user] Trouble writing to Accepted Socket stream
T Lee Davidson
t.lee.davidson at gmail.com
Fri Mar 29 23:25:10 CET 2019
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
More information about the User
mailing list