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.
Related
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.
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
Just some concept about TCP Socket, let's say there are 100 clients simultaneously communicating with a traditional HTTP/TCP web server. How many sockets are respectively at the server and at each client? Do all of the sockets at the server
have the same server-side port number?
The question is generic, so the answer is going to be as well.
For traditional TCP-based HTTP server, there will be 100 sockets on the server (one for each client), and one socket on every client. All server sockets will be bound to the same server port.
This answer doesn't take into account the fact that in modern HTTP model a client usually opens more than one socket to serve a single request.
I have to make an app using C/PHP sockets on linux that sends data from one socket to other socket, like this.
I have server (server_hosted) hosted somewhere with an IP or domain name. It is running web application.
I have another server (unknown_server) running at my home (unknown IP).
Client send some information through web application hosted in server_hosted to another server running at my home (unknown IP).
I need a way to established a connection between server_hosted and unknown_server.
I was able to make connection between both using TCP socket. I made server_hosted as server listen to certain port says 8080 and unknown_server as client, which make open connection to server_hosted.
The problem comes when I have multiple unknown_server at my home. How can I made connection to same port? How many client can TCP/IP support?
Any ides how to make tunnel or connection between server_hosted and unknown_server.
Is possible to do with curl or socket any better ideas?
I am trying to wrap my head around network sockets. So far my understanding is that a server creates a new socket that is bound to the specific port. Then it listens to this socket to deal with client requests.
I've read this tutorial http://docs.oracle.com/javase/tutorial/networking/sockets/definition.html and it says
If everything goes well, the server accepts the connection. Upon acceptance,
the server gets a new socket bound to the same local port and also has
its remote endpoint set to the address and port of the client. It needs
a new socket so that it can continue to listen to the original socket for
connection requests while tending to the needs of the connected client.
Here are a few things that I don't quite understand
If everything goes well, the server accepts the connection.
Does it mean that a client request successfully arrived at the listening socket?
Upon acceptance, the server gets a new socket bound to the same local port and
also has its remote endpoint set to the address and port of the client
The new socket is created. It also gets bound to the same port but it doesn't listen for incoming requests. After server processed client request resonse is written to this socket and then it gets closed. Is it correct?
Does it mean that request is somehow passed from the first socket to the second socket?
It needs a new socket so that it can continue to listen to the original
socket for connection requests while tending to the needs of the connected client.
So, the new socket is created then that listens for incoming request. Are there different type of sockets? Some kind of "listening" sockets and other?
Why does the server have to create a new listening socket? Why can't it reuse the previous one?
No. It means that an incoming connection arrived at the server.
No. It gets closed if the server closes it. Not otherwise.
No. It means that the incoming connection causes a connection to be fully formed and a socket created at the server to represent the server-end endpoint of it.
(a) No. A new socket is created to receive requests and send responses. (b) Yes. There are passive and active sockets. A passive socket listens for connections. An active socket sends and receives data.
It doesn't have to create a new listening (passive) socket. It has to create a new active socket to be the endpoint of the new connection.
Is new socket created for every request?
Most protocols, for example HTTP with keep-alive, allow multiple requests per connection.
1) An incoming connection has arrived
2) Socket doesn't get closed
3) There is server socket and just socket. Server socket.accept returns a socket object when a client connects