Purp Posted August 10, 2007 Don't think I've ever asked anything about HTTP here before, so I'm not sure whether or not to expect an answer. I've just released a new HTML-based chess game on my site: LP-WebChess It's working and I don't think there are many (if any) bugs at the moment, but I'd like to be able to make it automatically refresh the game page whenever the other player makes a move. I know there's nothing that I can put into the HTML to make this work because it can't tell when the other person's made their move, but I'm wondering if there's an HTTP command that can be sent, from my server, to a client using "Connection: Keep-Alive" to make it refresh the page. Anyone have any ideas? 0 Share this post Link to post
Purp Posted August 10, 2007 Yeah, I would try that, but I wanna keep it as close to pure HTML as possible and it would be hard to use that with my server. I wrote the server so it only understands what I understand (which admittedly isn't much), so the only way I can make this work really is if there's an HTTP command for refreshing. 0 Share this post Link to post
Manc Posted August 10, 2007 a 2 second google search turned up this: http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm Is that what you need? 0 Share this post Link to post
Purp Posted August 10, 2007 I was thinking of trying that, but that's just for delayed refreshing and I need it to refresh when my server tells it to (i.e. when the other player has moved). I think if I used the timed refresh thingy it would just annoy people because it would refresh for no reason when they were trying to do something. Edit: thinking about it though, that tag is an HTTP-equiv one so I guess that means it probably can be done. Now I need to work out how a connection that's been kept alive expects to receive it. Edit 2: ah no, I'm stupid. That can be used in an HTTP header but it's still just for refreshing after so many seconds. 0 Share this post Link to post
Maes Posted August 10, 2007 Well, that's how other "HTML based" games work (even though they are generated via PHP on the server side), there's no other way if you're not using some kind of active scripting language. 0 Share this post Link to post
Linguica Posted August 10, 2007 use ajax to seamlessly update the board every, say, 10 seconds without reloading the page as a whole, problem solved 0 Share this post Link to post
Quasar Posted August 10, 2007 I can't figure out AJAX. It scares me :( And of course it is different in every single browser 9_9 0 Share this post Link to post
Purp Posted August 10, 2007 Yeah, don't think I can do it then. That's what I thought in the first place. I might be able to use AJAX if I change a few things, but one problem is it's not just the board that needs updating - there's text telling you who's move it is and how long they've got, etc. and there's also a move log. Doesn't really matter anyway - none of the HTML ones I've played before updated automatically, cos HTML chess games are generally meant for long games, meaning ones that last several days or weeks. And I'm planning on going back to an older chess project some time and actually finishing it, and that's a proper application, rather than being web-based, so people can use that for short games. 0 Share this post Link to post
Jonathan Posted August 10, 2007 HTTP is all client-initiated, there's no capability for the server to push data to the client. Quasar said:I can't figure out AJAX. It scares me :( And of course it is different in every single browser 9_9 AJAX is nothing to be scared of. Yes, browsers are subtly incompatible in different ways, but that's why there's a wealth of free Javascript libraries that have sprung up in the last few years to abstract away the differences and let you get on with writing code. I'm not convinced on the efforts to write complex apps like office suites, but an online chess game seems like an ideal candidate for AJAX. 0 Share this post Link to post
Linguica Posted August 10, 2007 Quasar said:I can't figure out AJAX. It scares me :( And of course it is different in every single browser 9_9 http://code.google.com/webtoolkit/ 0 Share this post Link to post
Jonathan Posted August 11, 2007 Linguica said:http://code.google.com/webtoolkit/ Ugh, I say stay away from GWT. It's a sop for Java developers who are too scared or stubborn to learn Javascript. JS may have a bad reputation, but it's actually a pretty decent scripting language, and like it or not it's becoming a more and more important skill for developers to have. 0 Share this post Link to post
Purp Posted August 11, 2007 Actually, using the timed auto-refresh seems to work quite well. I've just added it as an optional thing on the Settings page. Works better in Firefox than in IE but should be ok in IE as long as you don't type too many messages or look at the move log (because it goes back to the top of the page every time it refreshes). 0 Share this post Link to post