web based game in asp.net?

rouncer 103 Dec 21, 2011 at 10:13

I know a little of asp.net, but one thing is bugging me before I write a simple multiuser dungeon with it, the fact that you can only refresh the html when the user clicks a button to, it cant be automatically triggered from the server… or can it? Does anyone know this?

Or is php or some other language something I should use, cause it enables this “auto resend updated page”

Thats the thing thats bugging me at the moment, without it the game is just about working, but with only a really nasty “click me updated” and you could dead if you dont click it every now and again…. just in case a monster starts eating your toes off, youd never know until you clicked “update” which makes no sense at all.

6 Replies

Please log in or register to post a reply.

vrnunes 102 Dec 21, 2011 at 11:04

You add some Javascript to make things dynamic… both in ASP.net and PHP.

Javascript setTimeout()


rouncer 103 Dec 21, 2011 at 12:28

Yeh I heard! cool, so ive got to go study some javascript then…

geon 101 Dec 21, 2011 at 13:46

You can absolutely have the server update the page continuously. It is called “Comet”. Some languages are not a very good fit for this, though, like PHP. PHP will usually have a execution time limit of 30 seconds or so. It an be configured, but most web hosts won’t let you.

If you can tolerate some lag, it might be a better idea to have the clients poll the server periodically, say every 10:th second. You would do this with javascript, using a technique called “Ajax”.

You will need to learn some Javascript, but whatever you do, don’t try to learn from any examples older than 2008:ish, avoid “W3Schools” and never use the “eval” function.

Javascript is virtually unchanged since it first appeared, but it seems everyone would write TERRIBLE cdoe in it until just a few years ago.

Oh! Andlearn jQuery! It will save you hours and hours of pain, and teach you good functional design.

rouncer 103 Dec 21, 2011 at 14:16

cheers geon for the advice, I guess it would be more bandwidth hungry than a client server exe setup, where you could compress and decompress messages, and really cut them down, how much extra bandwidth do you waste sending html?

alphadog 101 Dec 21, 2011 at 18:00

COMET is a generic term for any asynchronous information fetching. It’s also known as HTTP streaming. An HTTP server can be set such that connections do not timeout and keep flushing buffers such that the client can make use of constant flow of info.

It is likely to be upstaged by HTML5’s Websockets, so make sure you consider that too.

Of course, what you want to use is a cross-platform, cross-browser framework that abstracts COMET, Websockets and other solutions (like long-polling, which has nothing to do with pron), ex: orbited.

Also, the HTML5 spec has another possible “tool” called Server-Side Events, which is unidirectional push from server to client.

geon 101 Dec 22, 2011 at 11:47


how much extra bandwidth do you waste sending html?

l would not send HTML. It would require your server to know about the document structure of the client page, which duplicates a lot of code. Send pure data instead. A great format is JSON (Javascript Object Notation). It is pretty standardized, and jQuery has built in support for it. When I code PHP, I use the function json_encode() to dump PHP objects straight to JSON. Very, very useful.

The format is basically

  memberName: "some string",
  anotherMember: 1234,
  yetAnotherOne: ["an", "array", "of", "strings"]

So when you recieve the data on the client you just access it like an ordinary javascript object:

function myAjaxCallback(data){

The wasted bandwidth wouldn’t be that bad. Basically HTTP headers + the raw data in text format + whatever member names you use. It would compress pretty well too, if you enable gz compression on the server. I know Apache supports that. It is part of the HTTP protocol.