<div dir="ltr"><div>MySock_Ready, instead of Socket_Ready?</div><div></div><div>Why there is out commented write in read event?<br></div><div><br></div><div><br></div><div>Jussi<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 30, 2019 at 12:26 AM T Lee Davidson <<a href="mailto:t.lee.davidson@gmail.com">t.lee.davidson@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I'm using ServerSocket to listen for connections on localhost:8080. When I make a request to that URI with my browser, it just <br>
hangs, "Waiting for localhost..."<br>
<br>
In the ServerSocket.Connection event, I accept the connection which creates a Socket object to manage that connection. The issue <br>
seems to be that the accepted socket stream never becomes ready for writing unless I actually try to write to it. If I then <br>
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 <br>
endless loop that doesn't give up until around 23000 iterations.<br>
<br>
[code]<br>
' Gambas module file<br>
<br>
Private hServerSocket As ServerSocket<br>
Private MyConn As Socket<br>
Private crlf As String = Chr(13) & Chr(10)<br>
Private sResponse As String = "HTTP/1.1 200 OK" & crlf & crlf & "Hello world!"<br>
Private Count As Integer<br>
<br>
Public Sub Main()<br>
<br>
   hServerSocket = New ServerSocket As "MySock"<br>
   hServerSocket.Type = Net.Internet<br>
   hServerSocket.Port = 8080<br>
   hServerSocket.Listen<br>
<br>
End<br>
<br>
Public Sub MySock_Connection(RemoteHostIP As String)<br>
<br>
   MyConn = hServerSocket.Accept()<br>
<br>
End<br>
<br>
Public Sub Socket_Ready()<br>
<br>
   Print "Socket READY."<br>
<br>
End<br>
<br>
Public Sub Socket_Read()<br>
<br>
   For Each sLine As String In MyConn.Lines<br>
     Print sLine<br>
   Next<br>
<br>
   ' Print "Writing to stream."<br>
   ' Write #MyConn, sResponse, Len(sResponse) 'Socket not ready for writing until here.<br>
<br>
End<br>
<br>
Public Sub Socket_Write()<br>
<br>
   Print "Socket ready for writing."<br>
   ' Inc Count<br>
   ' Print Count<br>
   ' Write #MyConn, sResponse, Len(sResponse) 'Nearly endless loop created here.<br>
<br>
End<br>
[/code]<br>
<br>
What am I doing wrong?<br>
<br>
<br>
___<br>
Lee<br>
<br>
<br>
----[ Gambas mailing-list is hosted by <a href="https://www.hostsharing.net" rel="noreferrer" target="_blank">https://www.hostsharing.net</a> ]----<br>
</blockquote></div>