Skip to content

Client Server Communication using ZeroMQ

Client_Server_Communication_using_ZeroMQ.jpg

Introduction

ZeroMQ  is a messaging library, which permits an effortless way of designing a complex communication system. With support of ClrZmq in C#  it simplifies Client Server communication which is based on Request/Reply Pattern enabling 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

Image

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 get connected to server with socket.Connect () method.

Image

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,

Image

Image

Output

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

Image

Conclusion

ClrZmq could very well be the new way in how we 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 .

Phenomecloud 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

@ 2024 Phenom Enterprise Cloud. All Rights Reserved.