Forums - Open Redstone Engineers
Javascript in-browser multiplayer - Printable Version

+- Forums - Open Redstone Engineers (https://forum.openredstone.org)
+-- Forum: Off-Topic (https://forum.openredstone.org/forum-4.html)
+--- Forum: Programming (https://forum.openredstone.org/forum-8.html)
+--- Thread: Javascript in-browser multiplayer (/thread-9220.html)



Javascript in-browser multiplayer - ddthj - 01-25-2016

So I'm pretty completely new to web development but I have done some programming in python/java in the past.

I'm looking to create a website where users can get together in lobbies where they can play a multiplayer card game against each other (like double solitaire, if any of you know what that is)

The card game is not turn-based, so things move pretty quickly and a lot of cards are moved around simultaneously.

Where do I start? I can figure out some of the simple javascript for the cards themselves, but communicating quickly back and forth between the server, making the server itself, and creating the lobby system is what I don't know how to do.

Any help would be appreciated.


RE: Javascript in-browser multiplayer - PabloDons - 01-25-2016

So there are a few things you need to get figured out, then it will be smooth sailing from there:
1. Creating a server
This is not simply make a program listen on a port and send random data. It needs to be threaded so that each thread can listen for a specific client. I also needs to work with javascript's wonky websocket interface. Google it, javascript needs a certain form filled when creating a connection. I don't understand it, I just sort of accepted it.
2. Manipulating html with javascript
In javascript, you can edit the site's html on the client-side. I assume you already understand this, but I will mention it anyway. there is an object (kind of) called document where all the html resides. It has a method "querySelector()" that takes in a string which is the selector. It works exactly like the css selector. It returns an array of type element objects which are basically html objects. these elements have methods/variables such as attributes, style, innerHTML, etc. using an API such as jquery makes things much easier.
3. php & mysql
This is not a must have, but it's good practice. writing data into a mysql database is much more efficient than making files and opening them and reading/writing. PHP is a programming language designed to pre-process a document before sending to recipient. That means each time someone requests a webpage, the respective php script is run in order to output an html document which is then sent to the recipient. This is useful in order to have a sentral database of cards or users(?). You don't need to use PHP (in fact, if you can avoid it, by any means do so), but it's just too easy to install to really worry about it. All you do is simply install a linux package (or if you are using windows, simply an installer).
4. Google
This might sound silly, but it's extremely important. You must know how to use google efficiently. If you are having trouble, learn everything you can about the error before attempting to google it. You might even figure out the solution by trying to understand what the error is trying to say. Also, include error codes and learn what they really mean, they can help a bunch with the problem.

Hopefully you found this wall of text helpful. There is not much else I can tell you that you can't otherwise easily find on the web.


RE: Javascript in-browser multiplayer - ddthj - 01-25-2016

More questions:

1: I assume that the server that hosts the website will differ from the one that uses websockets to talk to clients?

2: I should be able to use a python server to handle the wonky javascript websockets, right?


RE: Javascript in-browser multiplayer - PabloDons - 01-26-2016

1: Yes, Website host is just delivering an html file for chrome/others to read and display. Websocket server is actually supposed to be talking to the client constantly, It's pretty much exactly like IRC, except you create the communication format.
2: You can literally use anything that can open a socket and listen on ports. Python definitely can. All languages you know probably can too.