Socket server in Javascript (in browsers)?

I wanted to allow users to play p2p in the multiplayer game that I am developing, but in order to do this, javascript must be able to create a socket server in the browser. Is it possible? I do not know any API that allows clients to connect to other clients in javascript. Is there any other way? How to use hidden flash element?

I am asking for something that does not require a server at all. Packages must be transported from client to client directly.

+6
source share
7 answers

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

Closest you can use NodeJS (for potentially p2p JS) or a centralized server (or multiple servers) and websockets (for sockets in the browser).

+6
source

An interesting question, but probably a duplicate:

I know for sure that this cannot be done using only javascript (in every browser). According to another answer in Stackoverflow in the topic above, you can do this using rtmfp-api .

This project provides the Rtmfp protocol (provided by Flash version 10) to javascript through a hidden flash applet. The protocol allows multiple clients to communicate directly. See References for more on the protocol.

If you quickly look at the site, you still need the rtmfpUrl server in the middle, which I fully understand, because clients must be able to find each other (IP). But I guess it will be p2p. Performing a quick search, I also found open-source rtmfp-server (s) .

I have not tried this myself, but maybe it will help you achieve your goal.

Some other links:

+4
source

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

Take a look here:

WebRTC Data Channels

Online example: Banana Bread 3D is a first-person shooter game compiled in JS + WebGL using WebRTC data channels in multi-user mode:

BananaBread 3D Massively Multiplayer Online Game fps

+4
source

While this is a purchase issue, I would look at APE

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

At least you can check how they structured it.

0
source

To implement such a game, your JavaScript client must interact 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
  • The server ensures that the input is valid (to prevent cheating) and updates the game with new input
  • The server periodically sends the game state to JavaScript (either with a long poll or with a JS request at intervals).

Basically, never trust anything coming from JavaScript, as it is very easy to modify it. Everything must be done on the server side.

0
source

Here's a solution with mobl (but I haven't tried it yet).

http://zef.me/3391/moving-the-server-to-the-browser

0
source

You can work without a server without Flash. This can be done using the features of Adobe Flash Peer to Peer. I once wrote a colleague to talk to him. The downside is ActionScript - it is a dying language and may not be supported in the future.

Here is the raw class. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetGroup.html

Here are the resources if you do not want to write your own. http://www.as3gamegears.com/category/multiplayer/

If you want the server to have the option "Server". Try this extension node.js.
http://socket.io/

I recommend using some kind of java socket server. Electroserver used to be one of the leaders in this area, it supported Unity and was scalable to hundreds of thousands. Although I think they fell in difficult times. Site Electroserver is not yet available. I know there are others, but Electroserver is the only one I used.

0
source

Source: https://habr.com/ru/post/913879/


All Articles