Socket and peer-to-peer connection at once - sockets

Is it possible, to mix a socket connection and a peer-to-peer connection within the same script? Let's say a chat application is running on socket.io and the 1 on 1 private messaging should be done within a peer-to-peer connection: Is it necessary to disconnect the running socket.io connection then?

It's both possible and super common. In fact, it's hard to establish a WebRTC peer connection without having a socket connection first.
This is because WebRTC requires exchanging offer/answer SDP and trickle-ICE messages between the peers ahead of establishing a direct connection.
The MDN tutorial does exactly this. Click on a username in the chat to establish a private video call (demo).

Related

Is there a C# library to manage a point-to-point socket connection with a unknown remote end?

I am developing an application which will open TCP/IP sockets to remote locations. For each of these connections, messages will flow in both directions asynchronously. There isn't any request-response behavior.
I've been looking at NetMQ and I like the way it manages the connecting and listening of sockets as well as the way it does the frames. But I don't see how it can work with a remote endpoint that doesn't run NetMQ.
Would defining my own socket type work? e.g.
public class MyNetMQSocket: NetMQSocket

Can Kurento run as a WebSocket client?

I understand that Kurento Server is called this way for a reason, but can it be configured (or hacked) to run as a client in terms of the Kurento Protocol?
According to the Kurento 6.6.1 documentation:
Previous to issuing commands, the Kurento Client requires establishing
a WebSocket connection with Kurento Media Server to the URL:
ws://hostname:port/kurento
But since we would like to run our Kurento Server behind NAT that doesn't have a dedicated IP address and doesn't allow DDNS and port forwarding, it would be really nice if Kurento could connect to our signaling server (WebSocket-based) and permanently sustain that connection. When web-based client connects to that signaling server, a connection would be negotiated between the WebRTC server (Kurento) and the client (browser) via signaling. – Well, that's our hope, at least, since RTSP connection to our camera also cannot be established from the Internet.
See the diagram of what we are trying to achieve:
Thanks.

Client to Web socket server to socket client implementation

I am trying to build a application that be behave as server and client that will be written in go.
as a big picture,
web/php websocket client(java script to websocket access) <-> go server(websocket server & socket client) <-> tcp socket server
For starting, I have implemented go to be a socket client, built protocol layer to communicate properly with my socket server and I have used some web socket library to be a websocket server.
My question is how can I pair each connection in secure way and manage connection without hassle.
I was thinking something like pair data structure to tack.
in go-lang syntax
var track_connection map[wss_connection]socket_connection
// create map data with web socket to be a key and track socket connection
this way i can look up the connection by web socket connection.
I am not sure this is clear enough to be a question
please let me know if any clarification is needed.

Does Photon Server supports multiple protocol connections?

I need to connect Unity3D client to Photon Server using both UDP and TCP connections. Is it possible? Where can I read about it?
P.S. I want to use TCP to send large amount of data.
Photon server supports multiple protocols simultaneusly. If you downloaded the server sdk
look for the PhotonServer.config:
It contains entries like this
<UDPListeners>
<UDPListener
IPAddress="0.0.0.0"
Port="5055">
</UDPListener>
</UDPListeners>
and
<TCPListeners>
<TCPListener
IPAddress="0.0.0.0"
Port="4530"
PolicyFile="Policy\assets\socket-policy.xml"
InactivityTimeout="10000"
>
</TCPListener>
</TCPListeners>
Your clients can connect per udp or tcp and interact with each other no mater what protocol thy have chosen.
For the full set of configuration options you can look here: http://doc.exitgames.com/en/onpremise/current/reference/server-config-settings
When a client connects you can query in your server side application how the client connected like this:
public class YourApplication : ApplicationBase
{
if (initRequest.LocalPort == 5055)
{
//
}
if (initRequest.PhotonPeer.GetListenerType() == ListenerType.TCPListener)
{
//
}
Note: UDPListener in the config are represented as ListenerType.ENetListener in code.
You can find the server sdk documentation in the downloaded {sdk}\doc\Photon.SocketServer.chm or online here http://doc-api.exitgames.com/en/onpremise/current/server/doc/annotated.html
Simple answer: No. A photon server cannot have more than 1 type of connection.
However, there is a way to do this depending on your definition of a 'server.' For the basis of this explanation, lets call a server the object instance running on a machine. The machine the server is running on, we'll call the machine. You can have multiple servers running from a single machine where they can have different types of connections. For instance, you could have the unity client connect to the physics server using a UDP connection and connect the client to whatever else you needed using a TCP connection.
Photon server handle connect object called Peerbase. Each peer is each client connection. In client peer connection you only choose protocol is UDP or TCP.
Solution is create two peers, one is UDP and one is TCP but hard to handle what UDP and TCP peer is in one client to find player info and send data

Using one socket for peer to peer communication

I want to write a peer to peer network application and have the following problem.
Two nodes in the network, A and B are trying to establish a connection to each other at the same time. When they both accept the connection of the other, there will be two TCP sockets opened.
Only one socket should be used for the communication between the two, because it is enough to communicate in both directions. What is an elegant solution to this problem?
Thanks!
You should not be trying to establish two simultaneous connections at the same time. That is a flaw in your p2p design. The two peers need to coordinate with each other (such as by exchanging messages via a central server that they are both connected to and knows who they both are). A decision needs to be made first about who is listening and who is connecting. One peer only opens a listening socket and that info gets sent to the other peer so it knows where to connect. If that conection fails (ie, the listening peer is behind a NAT/firewall), the peers need to be notified and a decision made to swap roles. The previously-connecting peer now opens a listening socket and that info gets sent to the previously-listening peer so it knows where to connect. If that connection fails (ie, the now-listening peer is also behind a NAT/firewall), then a direct connection between the two peers is not possible without additional help (NAT hole punching, for instance). In some situations, a direct connection is simply not possible, so data being exchanged between them would have to be proxied through the central server.