On 30/05/2011 00:36, Björnke von Gierke wrote:
As you noticed, webservers are really bad at sending data to clients without
being prompted first. If you are free to use your own computer as server, i
suggest doing it like chatrev, having a server stack that is publicly available
on the internet. That way is the easiest way to avoid the statelessness problem
that webserver always have.
Absolutely. What he said !!
But if you don't have (or don't want to require) a private server, then
it is quite feasible to do it all with http.
You don't need to do simple "second-by-second" polling. You can do what
I call "slow polling" ....
I've done a simple proof of concept, but don't have robust or reliable
code. What I do is have the server store all "moves" (or in my case,
things the clients 'say') in a text file on the server; each time a
client says something, it is appended to the text file. Each client also
listens for updates, in a continuous loop, like
global gLast, gLastUrl, gStop, gName
on mouseUp
put 1 into gLast
put false into gStop
put "http://www.tweedly.org/listen.irev?lastline=" & gLast into
gLastUrl
put gLastUrl after msg
unload URL (gLastUrl)
load URL (gLastUrl) with message "gotit"
end mouseUp
on gotit pUrl, pUrlStatus
if pUrlStatus = "cached" then
put URL gLastUrl into t
-- and do something with it
add the number of lines in t to gLast
unload URL (gLastUrl)
if not gStop then
put "http://www.tweedly.org/listen.irev?lastline=" & gLast
into gLastUrl
load URL (gLastUrl) with message "gotit"
end if
else -- no good data yet, try again
unload URL (gLastUrl)
if not gStop then
load URL (gLastUrl) with message "gotit"
end if
end if
end gotit
On the server, when a client asks for more data, it checks to see if
there is anything new;
- if there is, return it
- if not, wait for 1/2 second and then try again
<?rev
put $_GET["lastline"] into tLast
repeat with i = 1 to 100
put URL ("file:my.txt") into tData
if the number of lines in tData > tLast then
delete line 1 to tLast in tData
put tData
exit repeat
end if
wait for 100 millisec
put empty into tData
end repeat
if tData is empty then
put "no new data"
end if
?>
For the other questions:
I would make the server as simple and generic as possible. I would put
absolutely no game logic in it, so that one server would handle many
different games. I would not even give the server any concepts of
"turns", nor have the clients direct their messages to the opponent. I'd
have each game have an identifier, and have every 'move', and every
'listen', include that identifier as a url parameter (and use that game
id as the name of the file to store the moves on the server). That way,
you can have 2-player or mulitple-player games, you can add text chat,
etc. without changing the server.
-- Alex.
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode