[Gambas-user] Trouble writing to Accepted Socket stream
Cedron Dawg
cedron at exede.net
Sat Mar 30 00:27:51 CET 2019
Besides being single socket....
I don't think you are implementing the HTTP protocol, or I don't see it. I don't remember it that well either, sorry.
To get you started: https://www.w3.org/Protocols/rfc2616/rfc2616-sec1.html
I'm pretty sure the browser is waiting for you to send it a greeting as soon as you recieve the connection.
You might want to try using Telnet for a client instead.
Some of the first code I wrote when finding Gambas was a simple Server and Client based on the examples. I'll attach those upon request.
Ced
----- 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 6:25:10 PM
Subject: [Gambas-user] Trouble writing to Accepted Socket stream
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 ]----
More information about the User
mailing list