Skip to content

Instantly share code, notes, and snippets.

@alwnraj
Created February 6, 2025 16:44
Show Gist options
  • Save alwnraj/b9efdd3d0d91322c35dfcc769cb19e3d to your computer and use it in GitHub Desktop.
Save alwnraj/b9efdd3d0d91322c35dfcc769cb19e3d to your computer and use it in GitHub Desktop.
// sender.py
#
# Hello World client in Python
# Connects REQ socket to tcp://localhost:5555
# Sends "Hello" to server, expects "World" back
#
import zmq
context = zmq.Context()
# Socket to talk to server
print("Connecting to hello world server…")
socket = context.socket(zmq.REQ)
socket.connect("tcp://136.165.47.134:5555")
# Do 10 requests, waiting each time for a response
for request in range(10):
print("Sending request %s …" % request)
socket.send(b"Hello")
# Get the reply.
message = socket.recv()
print("Received reply %s [ %s ]" % (request, message))
//receiver.c
#include <stdio.h>
#include <time.h>
#include <czmq.h>
int main()
{
char buffer [256];
void *context = zmq_ctx_new ();
void *server = zmq_socket (context, ZMQ_REP);
zmq_bind (server, "tcp://*:5555");
while (true)
{
int size = zmq_recv (server, buffer, 255, 0);
//if (size == -1)
// return -1;
buffer[size] = '\0';
printf("[Message Received] : %s\n", buffer);
}
zmq_close (server);
zmq_ctx_destroy (context);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment