Peter Hwang
Peter Hwang

Reputation: 991

Client and server model in a web game

Currently, I am developing a 2-player tetris game. Originally, I was planning to implement a client-server model in a mobile environment.

However, now I change into web game, which is accessible by a browser. Since I am not used to a web development, I want to know if client-server model is necessary in a web game.

To be honest, I am a little bit skeptical writing both client and server code since a browser does a job to connect to the server.

Is it possible to build a network-based game by using only one server without a client part?

Upvotes: 1

Views: 993

Answers (2)

Palu Macil
Palu Macil

Reputation: 1719

Well, in one sorta correct way, no, because you're not redesigning the browser, but nobody would say it like that. Web design includes a lot of code / markup used on the client (browser), and while your server is sending the browser the data, and that data is a mix of CSS, HTML, and JavaScript (as well as media like graphics and perhaps music), the browser is the piece of software doing the lifting on those pieces once it receives them. That data is selected by the server, so the logic for that is on the server, but this is what people would think of as "client design" in the context of a web application.

There are also a number of models (ways of arranging your programming designs) which would lead to cleaner code, and a lot of these would send a grouping of information (called a model) to the client (the browser) and then the browser would do some interpretation of how to use that data (called a view). This is a simplification since I don't think you're ready for a big dive into specific theories, but you could start with a JavaScript and HTML tutorial and then learn a server language:

Python is my favorite, but PHP is big as is Java (NOT to be confused with JavaScript), and I make my living doing C#. Really there are plenty of great choices.

One commentator recommended Node.js because you'd use JavaScript on the server with Node--just like for the client part (the response data you're sending to the browser). That's double duty, but I am partial to Python (as I said). Just pick something, and as you learn, you'll get to know what you like. If you change languages, it'll be easier to learn your second one.

Upvotes: 2

kdbanman
kdbanman

Reputation: 10557

Is it possible to build a network-based game by using only one server without a client part?

Nope. You need a client.

It doesn't matter if you're in the browser or writing a native application. Yes, the browser solves a lot of client problems for you - it implements HTTP for you, and it has display (CSS), content (HTML), and evented logic (JavaScript) that you can use. But you still need to write your client using those technologies.

Even if the browser exposed a call in javascript like this:

window.startPeterHwangsTetrisGame();

You still have a client. The client is 1 line of code, and it is exactly the above script*.

Realistically, you should look for a game-oriented web development tutorial and start there.


*(aside from the necessary HTML within which that javascript exists)

Upvotes: 5

Related Questions