Choosing a Template for Communication between Client and Server on ZeroMQ - c++

I am making an application in C++ for Windows, which consists of a Client and a Server. The Server manages the Device.
The Client sends to the Server commands like:
Start Device
Stop Device
Set Device Gain
Set Device bandwidth
Get Device status
Data must be transferred from the Device to the Client for display on the screen. Data is arrays of complex numbers. There will be a lot of data, since there can be several Devices.
I developed my own command format, which is converted to JSON and then to a string.
I'm having a hard time choosing a template for ZeroMQ sockets. For data transfer, I chose the PUB-SUB pattern: the Server is the Publisher, and the Client is the Subscriber.
For sending commands, I also chose the PUB-SUB pattern, but in this case the Client is the Publisher, and the Server is the Subscriber.
In both cases, all messages received by the Subscriber are queued and further parsed.
This approach is very primitive. Perhaps you can suggest me more advanced templates? It would be great with sample code for Client and Server.

Related

Client-Server - How do i filter only dedicated software sending data?

I am writing a server and client code where i want to identify on server side official client software sending data.
The protocol is text based, so anyone can write it's own client - and i want to keep it, but want to group the devices by "Official" / "Non Official" based on the 'fingerprint' of my official client application.
Question:
How can i filter out my clients from other clones sending?
I am thinking to send encrypted message from my client to SERVER using the same key, so once decoded if it's valid, then i know its my app code sending - but before i go this way, any other better ideas ?

How to synchronize timers of two programs

I am making an application where I have a client and a server. The client will send some coordinates to the server which will use those to move a robot. What I want is to synchronize the timers, used for time stamping log data, so that I can compare the input vs output. The communication is done through TCP/IP, and the client is done in C++ while the Server is in RAPID (ABB robotic programming language). My problem is that the timers are not synched properly.
Right Now the timers start when the connection between the two is established:
Server side:
ListenForConnection;
startTimer;
Client side:
connectToServer;
startTimer;
This does not work. Is there a technique to ensure that the timers are synchronized?
NB: The server can only be connected through LAN.
You need a protocol between client and server to pass the timestamp.
Right now, presumably you have a protocol for sending coordinates. You need to extend that somehow to allow one side to send timer information to the other side.
The easiest is if you have two way communication capability. In that case, the client does
Connect to server
Keep asking until the server is there
Server says "yes I'm here, the time is 1:00"
The client starts sending coords
If the server has no way to send to the client, then the client needs to send a timestamp from time to time, which the server recognises as being a time, not a coordinate. The two will not be synched until this happens the first time.

What kind of network protocol should be used in this scenario?

Well...
I am working with an mobile application and a web server.
A characteristic of my web server is that it generates different set of data randomly. In other words, I cannot predict when the server will have ready data to send to the mobile app.
On other hand, the mobile app need to receive all data that the server generates. An approach could be request multiple times to get all these data. Indeed, It isn't a good approach, because I don't know when request the data.
If the mobile app could listen the server, after one start request or keep on the connection, for example, the server could sent any set of data in any time.
The question is: What is protocol suitable to this situation? How could I use that? Examples?
Thank you!
You could create a persistent TCP/IP connection to the server and permanently listen for incoming data (using a custom protocol or propably something websocket based). However such a permanent connection might seriously affect your battery life if it's for a mobile device. You will also lose the connection if the operating system automatically shuts down your application because it's out of memory.
The default approach to this problem are Push notification / Push services, where your server sends a notification about new data to a server of the phone provider (e.g. Microsoft or Apple push server), and this server sends the notification (as well as notificaiton from other online services) to your phone.
Some info for Windows Phone:
http://msdn.microsoft.com/en-us/library/hh221549.aspx
http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff402558%28v=vs.105%29.aspx
Depending on how often you have new data both approaches can make sense.
WebSockets could be the answer: http://en.wikipedia.org/wiki/WebSocket
Specifically, for Windows Phone, there's a solution also: http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff402558(v=vs.105).aspx

Which threading model should be used to create a Feed Handler Or Adaptor

Hi to all the experts out there :)
This is my first question here.
Problem Description :
I have to write a Market Data Feed Handler. This is going to be a Windows Service, will be using two Sockets.
Socket A : For communication between Subscribing applications and Feed Handler (Feed Handler will be accepting the connection request and the Item Request).
Socket B : For communication between Feed Handler and External Market Data provider, like Reuters/Bloomberg.
In both the cases Request/Response will be using the same port.
Note : The volume of Data coming from the external system is low (External system will only send the information which has been subscribed for, at this point of time).
However later on we may want to scale it, some providers throw all the data, and Feed Handler has to filter out locally, based on the subscription.
My questions :
What threading model i should use?
Which I/O strategy i should use?
Keeping in mind both the cases, should i create separate Request/Response thread?
EDIT 1: After reading few tutorials on Winsock, i'm planning to use Event Objects for asynchronous behavior.
The point of concern here is that, a single thread should listen for incoming client connections (Accept them) and also Connect to other server, in turn send/recv on two different ports.
Thread A
1) Listening for incoming connections. (Continuous)
2) Receiving Subscribe/Unsubscribe request from connected clients. (Rarely)
3) Connect to the external server (Onetime only).
4) Forward the request coming from client to the external server. (Rarely)
5) Receive data from external server. (Continuous)
6) send this data back to the connected clients. (Continuous)
My question is can a single thread act as both Client and Server, using asynchronous I/O models?
Thanks in advance.
Deepak
The easiest threading model seems to be single threaded synchronous. If you need to implement a filter for a provider, implement that as a socket-in/socket-out separate process.

How to guarantee delivery of data in a Compact Framework Webservice call?

We have a mobile Application in a very unsteady WLan Environment. Sending Data to a webserver could result in a timeout or in a lost WLan connection.
How do we ensure, that our data is delivered correctly? Is there a possibility of having Web Services Reliable Messaging (WSRM) on the device?
MSMQ is no option at the moment.
WSRM isn't supported. A reliable mechanism is to ensure that either the Web Service responds to the upload with an ack after the data has been received (i.e. a synchronous call) or that when you start the upload you get back a transaction ID that you can then send back to the service at a later point to ensure that it has been delivered before local deletion.