Thread: live communication between 2 c++ programs

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    2

    live communication between 2 c++ programs

    Hi, I am looking for a good, fast method for communication between two c++ programs. I am making a 3D mouse pointer and need to send the three coordinates to another program that presents them graphically. At the moment I am using a file, but opening and closing a little file up to 40 times per second cant be ideal...
    At the moment it looks like this:

    Code to send coordinates in Prog1:

    Code:
    ofstream fout("c:\\xyz.txt");
    fout << x << " " << y << " " << z;
    fout << flush;
    fout.close();
    (x, y, z are doubles)

    Code to recieve coordinates in Prog2:

    Code:
    		
    ifstream fin("c:\\xyz.txt");
    		
    if(fin.good())
    {
           fin >> X >> Y >> Z;
    }
    	
    fin.close();
    Any better ideas?
    My googling before finding this forum suggested me sockets or pipes, but I cant get it working. Any example is welcome!

    Thanks!!
    /Tomas B

    EDIT: I am using Windows XP and Visual Studio 2005
    Last edited by necksnapper; 04-03-2007 at 07:34 AM.

  2. #2
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I'm not entirely sure but I believe you would use a socket library ify your intention is for two programs to communicate over a network.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    2
    no they are running at the same computer, thats why I didnt dig more into the sockets - because I realized it was supposed to be on different computers, but maybe it is possible to use sockets anyway?

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    86
    yes it is

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    http://msdn2.microsoft.com/en-us/library/aa363858.aspx
    Scroll down to the end, then read about mailslots and pipes.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    630
    Is there any portable way to do this? Maybe its possible with boost?

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Registered User
    Join Date
    Mar 2007
    Posts
    8
    You could also export the symbols from that program so that another pogram can read from it.

    Only problem is I am not entirely sure if a DLL has to be the link between the apps, or if you can do it app to app.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unkown Hang
    By Bladactania in forum C Programming
    Replies: 31
    Last Post: 04-22-2009, 09:33 AM
  2. Communication between programs?
    By johny145 in forum Windows Programming
    Replies: 3
    Last Post: 06-01-2005, 10:14 PM
  3. Looking for communication lib
    By BrownB in forum C Programming
    Replies: 3
    Last Post: 04-27-2005, 10:01 AM
  4. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 05:42 AM
  5. communication
    By in need of help in forum C Programming
    Replies: 3
    Last Post: 12-27-2002, 03:56 PM