Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Can u give me an idea how to implement this,weather it is feasible?
What problems will i face?

I have made a code for parsing data that i received from the machine.....

My code is something like this:-
C++
int main()
{
   // Initialize Winsock

   // Attempt to connect to server(machine from which i will get data)
   {
      //Run the ioctlsocket() command
      //Run the setsockopt() command
      // Connect to server.
   }
   
   //create thread
    while(1);
}

//Thread defination()
{
   while(1)
   {
      //send data to machine
      //receive data from machine
      
      if received bytes is equal to,what we want then call
      //function to parse the data and store it in a file
   }
}

What i have to do is:-

Use this code to run on approx 100 machine.
I will read the ip and port of the machine from database.

I am thinking o do it like this:
I will write a query which will return me the no(count) of ip and port in the database.
Then depending upon the count i will make thread for each ip and port,each thread will contain one more thread that will be used for sending and receiving data.

Is this the FINE solution?
Do i have to use any semaphore,mutexes?
What problems will i face?
Posted
Updated 17-Sep-12 5:29am
v3
Comments
Richard MacCutchan 17-Sep-12 11:47am    
It's almost impossible to answer this: "What problems will i face?"> The simple answer is: plenty. The detailed answer is impossible to guess.

You need to write a basic program that can connect to one of these devices and read the data, process it and store the information in your database. Then, when that is working, just add the code to do it in threads. If each thread has exclusive access to the client device then you should only need to synchronise when storing results to your database.
pasztorpisti 17-Sep-12 12:48pm    
If you are not good at socket or thread programming then its almost sure you will put in some bugs. If you are unlucky then some of the bugs will occur quite rarely (low reproduction rate) making it exceptionally hard to fix.

1 solution

Quote:
Do i have to use any semaphore,mutexes?

Unless you have resources that are shared between threads (and it does not appear that you do) then you don't need any form of locking, because there is nothing to lock.

I'm not quite sure I understand what you're trying to do, but I don't see anything obviously wrong with your plan otherwise.
 
Share this answer
 
Comments
Tarun Batra 17-Sep-12 10:58am    
Sir what did u was not able to understand?
lewax00 17-Sep-12 11:03am    
I see what you're doing, I just have no idea why. It looks like you're basically creating the same file in 100 different machines, there are easier ways to accomplish that (like just copying the file).
Tarun Batra 17-Sep-12 11:08am    
Sir let me explain you:- i will have one my system and 100 dialysis machine i will connect to dialysis machines through sockets(ip and port i will get from database),now i will send request to each machine and they will in respond give me some data and i have to parse the data and store it in a file for each machine as each machine will be connected to different patient and will give different data.Now is It clear?
lewax00 17-Sep-12 11:30am    
Ah the makes more sense, it sounded as if you were trying to make a file on each machine to store information about the sockets and IPs of all the other machines. In that case you might need to use something to control access to the file you're writing to if each thread writes to the file, or just use a database, because those generally handle multiple incoming writes well.
CPallini 17-Sep-12 16:11pm    
Basically you need a database.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900