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
Rubens
  • 14,478
  • 11
  • 63
  • 92
networks
  • 115
  • 2
  • 8
  • What is it you want this "broker" to do, exactly? What is the significance of the code you have posted? – Greg Hewgill Oct 03 '12 at 22:47
  • 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. – networks Oct 03 '12 at 22:49
  • 5
    It sounds like you might be looking for something like [zeromq](http://www.zeromq.org/), 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. – Greg Hewgill Oct 03 '12 at 22:52
  • 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. – networks Oct 03 '12 at 23:04
  • 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? – jla Nov 13 '12 at 19:05
  • yes thats it i have in my mind something like object request broker. – networks Nov 15 '12 at 05:49
  • 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"? – Martin Ba Jun 26 '13 at 19:28
  • Really, stop your pain and start looking at zeromq. – RickyA Aug 28 '13 at 15:24

2 Answers2

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

Tushar Jadhav
  • 335
  • 4
  • 14
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.

DougN
  • 4,407
  • 11
  • 56
  • 81