Is it possible to run a server and initialize multiple socket on the same port in Node? - node.js

I would like to create a server that listens on port 8080, for example. Then I would like to initialize multiple sockets using local port 8080 that connect to additional peers. The purpose of this is to create a peer to peer network, so peers listen on and initialize connections with other peers on the same port.

In order to perform peer to peer connectivity on web, you have to use WebRTC. This is also possible with socket.io. So actually you server won't listen to multiple sockets in same port, but act as a STUN/TURN server in order to introduce different clients. I have written a simple explanation in this article. Please read it for further clarifications.
In a peer to peer network you may have to write the code in client side, (since the server may not control the network after peer discovery) instead of writing login in backend.
Also follow this article for more information about how develop WebRTC network with socket.io.

Related

Python3 - Port forwarding using UPNP using sockets to make a peer to peer network

I've messed around with sockets for a while and in order to forward a port, I need to port forward on my router as well as open the port on my windows firewall. I'm trying to set up a peer to peer network using python3. I've heard that the only way to make this possible is to use UPNP. What packages would make this possible so that the peers don't need to configure their firewall or router? Thanks for your help <3

What is the difference between peer to peer and client/server connections?

I would like to know what is the difference between peer to peer and client/server connections for example i have 2 online games but one uses peer to peer and the other connects the client to the server and then retrieve the coords(example) to another player connected. if both type of connections have the same result what is the difference?
If I understand it correctly, client/server implies a request/response idiom: client makes a request, server sends response. There's no response from server to client without a triggering request.
Peer-to-peer means the communication is two-way: requests and responses can flow in both directions.

Is it possible to both listen and send messages to a remote socket using node-red's websocket node?

The Almond Plus router and home automation hub now exposes the state of its registered z-wave and zigbee sensors via a websocket.
The websocket API is here:
https://wiki.securifi.com/index.php/Websockets_Documentation
I've aimed a node-red websocket node at the router's local IP address, and have included authentication information in the URL. This seems to work for receiving status changes to devices.
But I need to also be able to send commands over the websocket to flip switches and whatnot. When I create both 'listen on' and 'connect to' websocket nodes in node-red, only the node that's listening connects. Do I need to make two nodes at all? I would have hoped there'd be a way to make one connection to the websocket and use it for two-way communication, but maybe this question just exposes my ignorance of how either websockets or node-red function.
Thanks for any help or information.
You should need both a Websocket in and a Websocket out, but both should be set to "connect to" mode. These handle the input and output side of the connection
I'd have to double check the code, but they should share the same client connection under the covers so there will only be one real Websocket connection. But even if the 2 nodes don't share the connection having 2 separate websocket connections to the same address shouldn't be a problem.

BitTorrent Local Peer Discovery when using SOCKS

I am writing a simple BitTorrent client with Local Peer Discovery and SOCKS5 support.
Are these technologies mutually exclusive? Should I disable Local Peer Discovery when using SOCKS proxy?
Are these technologies mutually exclusive
No. You can open regular sockets to listen for local connections found via LPD and use SOCKS for proxied connections.

Is it possible to create peer-to-peer connections in different network?

I want to create peer-to-peer connections between 2 nodejs client.
using websocket (dnode)
here is the limit:
nodejs client run at 2 pc which is in different network.
they don't have static ip (192.168.1.100 && 192.168.2.200) behind NAT or firewalls
no permission to change the mapping of router.
has only static web server in public network. (can change the file by human)
can install application at pc (win)
is it possible? thanks
May be you can use PeerJS to achieve your objectives.
PeerJS simplifies WebRTC peer-to-peer data, video, and audio calls.
PeerJS wraps the browser's WebRTC implementation to provide a complete, configurable, and easy-to-use peer-to-peer connection API. Equipped with nothing but an ID, a peer can create a P2P data or media stream connection to a remote peer.
Also to broker connections, PeerJS connects to a PeerServer. Note that no peer-to-peer data goes through the server; The server acts only as a connection broker.
If by peer to peer connection, you mean direct connection between the peers (i.e., not via a server) then yes it is probably possible in theory in most cases. But I have never seen someone who has implemented the solution.
You would need to implement a NAT hole punching system for TCP connections (they are not always 100% successful because of technical constraints which can't be solved at the software layer). Then, you'd just need to implement the websocket protocol on top of this tcp connection.
If by peer to peer connection, your are ok that communication passes via a central server (with a public address), then yes it is possible too. Both peers just need to connect to the central server, and it should just transfert the traffic between both peer.

Resources