read from socket question
janschenkel at yahoo.com
Tue Oct 10 13:59:08 EDT 2006
--- kee nethery <kee at kagi.com> wrote:
> I am using Andre Garzia's wonderful RevHTTPd code to
> create a small
> slave server to provide a service for other master
> servers. In
> general it works well except, one of the master
> servers does
> something funny but totally legit when it sends a
> POST to the slave
> RevHTTPd server and most times the RevHTTPd server
> deals with it, and
> sometimes not. This is a read from socket question
> and I could use help.
> The slave server code is very simple:
> on httpStart
> accept connections on port 8080 with message
> end httpStart
> on newConnection pSocketID
> read from socket pSocketID with message
> -- message is actually doing a "processRequest
> pSocketID,it" where
> it contains all the data gathered by the socket.
> end newConnection
> on processRequest pSocketID, pSocketData
> global theSocketData
> put pSocketData into theSocketData
> -- then from here on down it parses theSocketData
> and does a reply
> to the master server
While I was building the database router server app
that I showed at RevConWest, I encountered similar
problems. Try something like this:
local sSocketDA -- data array
accept connections on port 8080 \
with message "newConnection"
on newConnection pSocketID
read from socket pSocketID until CRLF \
with message "ReadRequest"
on ReadRequest pSocketID, pSocketData
put pSocketData into sSocketDA[pSocketID,"request"]
read from socket pSocketID until CRLF & CRLF \
with message "ReadHeaders"
on ReadHeaders pSocketID, pSocketData
put pSocketData into sSocketDA[pSocketID,"headers"]
read from socket pSocketID until empty \
with message "ProcessRequest"
on processRequest pSocketID, pSocketData
put sSocketDA[pSocketID,"request"] & CRLF & \
sSocketDA[pSocketID,"headers"] & CRLF & CRLF & \
pSocketData into theSocketData
-- ... carry on and process ...
This approach seems to give the sockets breathing
room. For extra safety, you could parse the headers,
look for the Content-length header and read from the
socket 'for x chars' instead of 'until empty'.
Don't forget to clean up the data in the array after
you've written back the result, of course ;-)
Hope this helped,
Quartam Reports for Revolution
"As we grow older, we grow both wiser and more foolish at the same time." (La Rochefoucauld)
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
More information about the Use-livecode