Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Purp

HTTP question

Recommended Posts

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?

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

use ajax to seamlessly update the board every, say, 10 seconds without reloading the page as a whole, problem solved

Share this post


Link to post

I can't figure out AJAX. It scares me :( And of course it is different in every single browser 9_9

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post
Linguica said:

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.

Share this post


Link to post

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).

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×