Middleware in client/server communication
Asked Answered
L

2

7

I'm building a client/server pair in C++, and I've used the winsock for the communication. However, I'm not able to find any library in C++ by which I can implement something that, instead of sending requests directly from the client to the server, will store the request, and will later communicate with the server.

Is there any method or library for sending the request to something like a broker, and vice-versa? Something that will store the request, and then will communicate with the server. These are the libraries I'm already using:

#pragma comment( linker, "/defaultlib:ws2_32.lib")
#include <WinSock2.h>
#include <winsock.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <windows.h>
#include <ws2tcpip.h>
#include <fstream>
using namespace std;

#define HOSTNAME_LENGTH 20
#define RESP_LENGTH 40
#define FILENAME_LENGTH 20
#define REQUEST_PORT 5001
#define BUFFER_LENGTH 1024 
#define TRACE 0
#define MSGHDRSIZE 8 //Message Header Size
Lotus answered 3/10, 2012 at 22:44 Comment(8)
What is it you want this "broker" to do, exactly? What is the significance of the code you have posted?Lipinski
i want this broker to accept multiple requests from client and then queue then and send them to server one by one to process the request. The significance of the code is that i am telling that i have used these libraries ..i want to know that is there any library in c++ for that or i can do something with winsock.Lotus
It sounds like you might be looking for something like zeromq, however that may be much more complex than you need. In simple servers, the server software itself will queue requests internally and act on them one by one if it needs to process requests strictly sequentially.Lipinski
ya i know that server does that but i need something in between the server and client to do that work. Like instead of server address client have the address of that broker for request sending.Lotus
I am also unsure what you have in mind when you say "broker". Are you looking for an intermediate service running in it's own process or thread that acts as a proxy? Are you looking for an in-process library that abstracts network communications (CSocket)? Is the point the queueing or the abstraction? Something as heavy as Object Request Brokers or some messaging protocol like AMQP or RabbitMQ?Ibiza
yes thats it i have in my mind something like object request broker.Lotus
IMO this question is still unanswerable because it doesn't really specify what is needed of this broker. An "Object Request Broker" as I unerstand it ia´s a separate process on a separate machine -- how would you handle this with "a library"?Turbojet
Really, stop your pain and start looking at zeromq.Heaney
E
0

What you need is to write your own library for achieving your goal. I don't see any practical use of having such "broker" which merely stacks up the requests and sends them one by one and hence there is none available commercially. You can write one and it won't be a hard task to do it if you really want such a thing. This maybe your application specific need and I would make your above WinSock code intelligent enough to handle it and avoid searching/ writing such a library.

You might also want to consider the microsoft REST HTTP library aka casablanca and read the below blog post before writing such a library.

http://blogs.msdn.com/b/vcblog/archive/2013/07/10/intercepting-http-request_2f00_response-using-c_2b002b00_-rest-http-library.aspx

Enticement answered 5/9, 2013 at 8:30 Comment(0)
V
0

What you are describing is message queueing. Look into MSMQ (Microsoft Message Queue) or RabbitMQ. This would allow your client apps to send a request to the queue. Then your server(s) would read requests from the queue and process them as appropriate.

Volva answered 23/4, 2016 at 15:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.