Skip to content

Client Server Communication using ZeroMQ

Client Server Communication using ZeroMQ | PhenomᵉCloud
Client Server Communication using ZeroMQ | PhenomᵉCloud

Client_Server_Communication_using_ZeroMQ.jpg

Introduction

ZeroMQ is a messaging library, which allows an effortless way to design a complex communication system. With support of ClrZmq in C# it simplifies Client Server communication, which is based on Request/Reply Pattern enabling the client to send the request and receive a response from the server. This blog illustrates client server connection and communication using ClrZmq in C#.

Process

The REP (response) socket is the "server" end of a REQ/REP setup (request/response), where you bind the server using a REP socket to an endpoint, either explicitly specified "tcp://127.0.0.1:5555" or using wildcards, e.g. "all interfaces", "tcp://*:5555". 

The client would then connect using a REQ socket to an explicit endpoint address, "tcp://127.0.0.1:5555", and no wildcards.

Connection

Every client who needs to communicate with the server must connect to the socket. The server and clients who participate in communication must connect to the same tcp connection address.

Server

socket.Bind ( "tcp://127.0.0.1:6000" );

Client

socket.Connect ( "tcp://127.0.0.1:6000" );

Any number of clients can be connected to the server with the socket. Connect () method.

Communication

Now server and clients are ready for the communication with the socket connection between them. Client sends and receives the Acknowledgement through socket as follows,

Output

Output screen grab looks like this with two clients and one server, participating in communication with ZMQ as the main communications layer.

Conclusion

ClrZmq could be the new way to connect our components. But while dealing with this, one should make sure the firewall is not blocking and see to it that the port is not already in use. For ZeroMq addressing rules, see the zmq_tcp API documentation, and for the socket, see the zmq_socket API documentation.

PhenomᵉCloud is an enthusiastic family of individuals, fervent to make lives simpler through effective use of technology. Our mission is to implement solutions that drives business results. Know more insights from our thoughts and experience.
 
Contact us today or call 1-855-978-6816 to talk with us about your business needs.

Leave a Comment