Click here to Skip to main content
13,054,329 members (126,674 online)
Rate this:
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
//Thread defination()
      //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
Updated 17-Sep-12 5:29am
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

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

Solution 1

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.
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 17 Sep 2012
Copyright © CodeProject, 1999-2017
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