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

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

Related

ZeroMQ broadcast to specific PULL client across firewall

I'm building a message broker which communicates with clients over ZeroMQ PUSH/PULL sockets and has the ability to exclude clients from messages they're not subscribed to from the server side (unlike ZeroMQ pub/sub which excludes messages on the client side).
Currently, I implement it in the following way:
Server: Binds ZeroMQ PULL socket on a fixed port
Client: Binds a ZeroMQ PULL socket on a random or fixed port
Client: Connects to the server's PULL socket and sends a handshake message containing the new client's address and port.
Server: Recieves handshake from client and connects a PUSH socket to the client's PULL server. Sends handshake response to the client's socket.
Client: Recieves handshake. Connected!
Now the client and server can communicate bidirectionally and the server can send messages to only a certain subset of clients. It works great!
However, this model doesn't work if the clients binding PULL sockets are unable to open a port in their firewall so the server can connect to them. How can I resolve this with minimal re-architecting (as the current model works very well when the firewall can be configured correctly)
I've considered the following:
Router/dealer pattern? I'm fairly ignorant on this and documentation I found was sparse.
Some sort of transport bridging? The linked example provides an example for PUB/SUB.
I was hoping to get some advice from someone who knows more about ZeroMQ than me.
tl;dr: I implemented a message broker that communicates with clients via bidirectional push/pull sockets. Each client binds a PULL socket and the server keeps a map of PUSH sockets so that it can address specific subscribers. How do I deal with a firewall blocking the client ports?
You can use the router/dealer to do this like you say. By default the ROUTER socket tracks every connection it has. The way it does this is by having the caller stick the connection identity information in front of each message it recieves. This makes things like pub/sub fairly trivial as all you need to do is handle a few messages server side that the DEALER socket sends it. In the past I have done something like
1.) Server side is a ROUTER socket. The ROUTER handles 2 messages from DEALER sockets SUB/UNSUB. This alongside the identity info sent as the first part of a frame allows the router to know the messages that a client is interested in.
2.) The server checks the mapping to see which clients should be sent a particular type of data using the map and then forwards the message to the correct client by appending the identity again to the start of the message.
This is nice in that it allows a single port to be exposed on the server. Client side we do not need to expose ports, simply just connect to the server ROUTER socket.
See https://zguide.zeromq.org/docs/chapter3/ for more info.

Socket and peer-to-peer connection at once

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).

What are options for finding a socket connection and then push data when your connections are spread across multiple hosts

I'm trying to build a web app that operates in real-time via a push model. I've used sockets in the past to achieve this, just not in a distributed service. My question is: Given that the host that receives the updated information (via Amazon
SQS) is not necessarily the host that the necessarily the host that
the web browser has a socket connection open with, How do we find the socket connection and then push the data.
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