Skip to content Skip to sidebar Skip to footer

Socket Server In Javascript (in Browsers)?

I wanted to be allow users to play p2p in a multiplayer game that I'm developing, but to be able to do that, javascript needs to be able to create a socket server in the browser. I

Solution 1:

In short no, p2p in a browser is not possible.

The closest you can get is using NodeJS (for potentially p2p JS) or a centralised server (or several servers) and websockets (for sockets in a browser)


Solution 2:

This question is old, but I can now give an answer: YES, there is finally a way to do p2p communication between browsers! Thanks to the new standard WebRTC, modern browsers got support for Data Channels, something much more powerful than WebSockets.

Take a look here:

WebRTC Data Channels

Online Example: Banana Bread 3D is a First Person Shooter game compiled to JS+WebGL, using WebRTC data channels in multiplayer mode:

BananaBread 3D Multiplayer online fps game


Solution 3:

Interesting question, but probably a duplicate:

i know for sure this can not be done using only javascript(in every browser). According to another answer on Stackoverflow in above topic you might be able do this using rtmfp-api.

This project expose Rtmfp protocol (provided by Flash version 10) to javascript application throught a hidden flash applet. The protocol allow multiple clients to communicate directly. See the references for more details about the protocol.

Looking quickly at the site you still need a rtmfpUrl-server in the middle, which i totally understand because the clients need to be be able to find each other(IPs). But I assume after that it will be p2p. Doing a quick search I also found open-source rtmfp-server(s).

I haven't tried this out myself, but I maybe this will help you achieve your goal.

Some other links:


Solution 4:

While this is a shopping question, i'd look into APE

http://www.ape-project.org/

At the very least you could check out how they've structured it.


Solution 5:

In order to implement such a game, your JavaScript client must communicate with the server. The server then runs the game logic, and sends the result back to the client.

  • JavaScript receives user input and sends it to the server
  • Server ensures that the input is valid (to prevent cheating) and updates the game with the new input
  • Server periodically sends the game state to JavaScript (either by long polling or by having JS request it at an interval).

Basically, never trust anything coming from JavaScript as it is extremely easy to modify. Everything should be done server-side.


Post a Comment for "Socket Server In Javascript (in Browsers)?"