Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:-
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 17-Sep-12 4:35am
Edited 17-Sep-12 5:29am
v3
Comments
Richard MacCutchan at 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 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Tarun Batra at 17-Sep-12 10:58am
   
Sir what did u was not able to understand?
lewax00 at 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 at 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 at 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 at 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)

  Print Answers RSS
0 OriginalGriff 318
1 Sergey Alexandrovich Kryukov 286
2 RyanDev 75
3 PhilLenoir 60
4 nv3 60
0 Sergey Alexandrovich Kryukov 6,691
1 OriginalGriff 6,119
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 17 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100