Define your own protocol to be used with the socket communication. Then send a packet when data has been updated by a calculation. The protocol should be able handle the possible amount of data that is updated by your calculations.
A possible protocol structure may be:
int updateType; // Identifies the struct member that is updated//int dataType; // Optional: Data type of struct member (float, char)int firstNdx; // First index for array data typesint lastNdx; // Optional: Last index (when multiple elements must be updated)int dataLen; // Optional: Size of following data ((lastNdx - firstNdx) + 1)// Multiply with size of data type for byte count char data; // Payload placeholder
The updateType may be an enum instead of an <code>int:
To create a protocol block calculate the amount of data bytes, allocate memory, cast it, fill it, and send it. Example:
int firstNdx = 0;
int lastNdx = 10;
int dataSize = ((lastNdx - firstNdx) + 1) * sizeof(float);
// Allocate buffer for protocol header and payload.// Using a buffer on the stack here would be faster but// requires the size to be known during compilation time.//char buf[sizeof(MyUpdateProtocol) - 1 + sizeof(float) * MAX_ELEMS_TO_BE_SEND];char *buf = newchar[dataSize + sizeof(MyUpdateProtocol) - 1];
// Cast buf to a protocol type pointer.
MyUpdateProtocol *pProto = (MyUpdateProtocol *)buf;
// Initialise the protocol header fields.
pProto->updateType = IVKK;
//pProto->dataType = MUP_FLOAT;
pProto->firstNdx = firstNdx;
pProto->lastNdx = lastNdx;
pProto->dataLen = dataSize;
// Copy the payload (pModDB is a pointer to the shared data).
memcpy(pProto->data, &pModDB->IVKK[firstNdx], dataSize);
// Send it.// Use the real size here (subtract one byte for the data member).
sendData(buf, dataSize + sizeof(MyUpdateProtocol) - 1);
delete  buf;
On the receiving side copy the data according to the protocol header fields:
// Assuming received data has been copied to char *buf
MyUpdateProtocol *pProto = (MyUpdateProtocol *)buf;
void *dest = NULL;
case IVKK : dest = &pModDb->IVKK[pProto->firstNdx]; break;
case FIL : dest = &pModDb->FIL[pProto->firstNdx]; break;
memcpy(dest, pProto->data, pProto->dataLen);
EDIT: LOL hadn't read Jochen's response who did it same way but with some nice protocol sizing. That is pretty nice makes the case statements on the copy enumerate easier. Anyhow you get the idea it isn't a hard task. I will leave the code so you can see what his protocol sizing is simplifying. Did you ever get the network transfer sorted?
Like the people said whats the problem?
You can just do as basic as memcpy I just grabbed your struct and made a zeroed instance and did it to show you.
Let me brief the architecture for your kind understanding
We have 3 applications involved.
1. Model (Runs along with the server and shares the data with Server through Shared memory. Changes the data through formulas and calculations continuously)
2. Server (Updates the data in the shared memory that is changed by the user for recalculation. Gets/Puts the data in shared memory and shares data with model. Also updates client with the updated data from model. Receives user changes from the client.
3. Client (Has number of GUI windows to show the values and receives values from user.)
The Server and the model runs locally and communicates using shared memory. The Client can run either locally or remotely within the network and the communication is using TCP/IP Sockets
I have 2 problems here.
We dont have hold with the model code. So I cannot detect the value changes from the model.
But both the model and the Server shares the same structure what I have mentioned previously.
So, Is it possible to detect the value changes through shared memory from the Server side?
As an example if I assume that every alternate member variable array(entire array) is changing, then I have to send 'n' number of times the data through the socket every cycle, where n is the number of member variable arrays in the structure. My concern is the load or performance problem that I had already faced while splitting the data as packets for sending every cycle. I am afraid if the same problem may occur if I send it 'n' number of times.
You try to detect whether an update has taken place from a remote station.
I take it that you are writing an Application where Clients access the database Direct.
You have two lines of defence here. the function 'stat' will give you the last modify time. If it has not changed since the last time you read it, or wrote to it, your private copy items are still in date.
What to do Next, if the File Stamp has changed. In any case, we need to reload the data, if it affects the records we are dealing with. A Simple check sum will do!
I think you have already worked out the problem it is going to take you a lot of power to work out what has changed in the mapped file.
The best approach but the hardest would be to intercept the Writefile calls from the Model application since you don't have the code. The process is called IAT patching and you hook the model application write calls and simply send the data for each write call to your client before letting it drop thru to write to the mapfile as normal. There are a couple of IAT patching articles right here on Code Project. It obviously has the massive advantage that effectively it slows the model program down if your update dispatch is slowed and there is no searching to be done you are transmitting the changes as they are made. The downside is this is not something a novice can code it requires a level of experience.
The second alternative is to make an application that simply cycles around comparing the mapfile comparing the mapfile to a local copy of the last scan thru the file and transmitting changes as it encounters them. So you have a local copy of the mapfile as you last visited this position as you then find a change you hold the position in the file and then keep reading while you have differences. All you do then is send a simple structure File position, size of change, change data to the client. Then you continue back to looking for a changes. All the client does is grab a packet, move to the position given and copies the changed data. So the client copy just changes slowly to mirror the server mapfile at whatever rate the packets can be sent. This is how remote terminal services work sending your screen to another user.
The downside of the second alternative is you will often get your fields having part of current data and part old data. For you that is not to bad because you know the structure layout so you can probably carry field flags to indicate if they are currently half changed because you in the process of writing them.
Anyhow whichever technique you use this will not be a trivial task
I was thinking a bit more about your problem and there is a possible all be it highly technical solution which is a thing called a file filter. It jogged my interest as to whether you could run a memory mapped file in a file filter so you can get all the raw file access commands and it appears you can
Hello, i've decided to code a application for our committees in our university section. The basic function of the program should be to inform students about upcoming events hosted by different student unions/committees.
Events will be stored in an SQL database. Every event will have a few datas like "Committee name" "Description of event" "Date". The idea is that the app will get all events from the database that hasn't already been. It will display these in a list inside the application. If a new event is uploaded to the SQL database the application will give away a push-notification. And user will be able to display it. I have experience in C.
My questions are
Is there good graphic libraries and is it possible to do this with ease in C++?
Is it possible to make a program like this work in Android and IOS?
Would also appreciate general tips for people that've made mobile applications
C++ is not very popular in standard mobile applications (and it is not recommended, see, for instance Getting Started with the NDK | Android Developers[^].
For the an Android platform, Java is the natuaral programming language (altough you migh as well use C# via Xamarin).
As CPallini said C,C++ coding of Android is not for the faint hearted and I would not recommend it as things stand at current.
I can offer you a funny way into the problem for a medium level programmer which is to use the free Unity game engine. You write in C# and can run your code and debug it as a windows application on windows. Then you just select the target as android and it does all the conversion and crossing to Android for you.
You have a bit of learning to do with the unity interface but there are plenty of tutorials. The SQL classes already exist as standards in Unity like they do in .NET and is rather trivial as most online games store data in/from server databases.
On the plus side all the finger swipe libraries exist already and you can develop a groovy application look on the UI using the graphics stuff
Yes, I agree Richard but unless someone has done some work since I last tried compiling the code samples for the API even it was not trivial. I lost hours of time playing around with it as I needed old frameworks as well as 5 or 6 newer ones. If they have not improved it I would rate it as needing expert level knowledge but you may have more recent experience.
I have been trying to create a puzzle that can solve itself using BFS algorithm. Currently, the search algorithm and the main but I don't know how to integrate both of them together.
// Program to print BFS traversal from a given source vertex. BFS(int s)// traverses vertices reachable from s.
// This class represents a directed graph using adjacency list representationclass Graph
int V; // No. of vertices
list<int> *adj; // Pointer to an array containing adjacency listspublic:
Graph(int V); // Constructorvoid addEdge(int v, int w); // function to add an edge to graphvoid BFS(int s); // prints BFS traversal from a given source s
this->V = V;
adj = new list<int>[V];
void Graph::addEdge(int v, int w)
adj[v].push_back(w); // Add w to v’s list.
void Graph::BFS(int s)
// Mark all the vertices as not visitedbool *visited = newbool[V];
for(int i = 0; i < V; i++)
visited[i] = false;
// Create a queue for BFS
// Mark the current node as visited and enqueue it
visited[s] = true;
// 'i' will be used to get all adjacent vertices of a vertex
// Dequeue a vertex from queue and print it
s = queue.front();
cout << s << " ";
// Get all adjacent vertices of the dequeued vertex s// If a adjacent has not been visited, then mark it visited// and enqueue itfor(i = adj[s].begin(); i != adj[s].end(); ++i)
visited[*i] = true;