Skip to main content
GameDev.net gamedev.net
🔒 Locked

2 programs chatting?

Started by Farraj Jan 13, 2007 at 11:05 PM 4 replies 1k views
Original Post
Farraj
Farraj
Hi. I got a question that’s been bothering for a long time now. How do 2 programs communicate and/or control each other on the same the computer?? For example, when you run most games now they open up some ‘configuration’ application first to configure the game. And when you press ‘start’ the application terminates and the game starts!!! I’ve also checked an engine that creates the gui, client and server on 3 separate programs (even for a single player game) that communicate with each other. The only thing that I can think of is this. When I was checking some Winsock tutorials they mention that setting the IP address to 127.0.0.1 will let the client send messages to the computer is working on. Is this how it’s done??? If that’s the case how would it run a program?? Thanks.
Telastyn
Telastyn
That could be how it's done.

For the configuration tool, it likely doesn't communicate... It likely just writes the configuration to a file and then spawns the application. Running the program is (usually) a simple system call (c/c++ system or exec... sort of functions [I can never remember exactly], unix scripts or perl use $cmd, .NET its... eh, Diagnostics.Process.Start)

It also might be just "simple" threading, an OS specific IPC setup...
Zipster
Zipster
You probably wouldn't want to use the networking interface for communicating across processes that will be strictly on the same machine. Some games use it even in single-player because they also include a multi-player component, and it simplifies the engine architecture to think of single-player as "multi-player with one person". Otherwise, you'd probably use files or messages or whatever other IPC services your OS provides.
AnthonyG
AnthonyG
In Windows, The programs start each other via CreateProcess(). Or as the previous member said, Invoke the command prompt via system() calls.

An easy way to communicate between processes is(Once again, Windows) via Mailslots. In fact, I recently worked on a project that contained a DLL, and a loader that injects the DLL into a process.

I wrote a MailServer class, and MailClient class, Each containing members to start/create a mail server, and write a message, and to read it.

The reason for this was to allow an easy way for the DLL to send log messages to the loader's "Console".

I don't know how much this will help you, but it should give you the general idea :)

First, The server class, The loader is the server in this case.

class cMailServer{private:	cDllLoaderUi iAction;	//----------------------	const char* vServerName;	HANDLE vMailHandle;	//----------------------	DWORD vMsgWaiting,vBytesRead,vBytesToRead;	char vMail[1000];public:	//Create the server	void mCreateServer();	//Write a message	void mWriteMail(char msg[]);	//Check the mail and write it to the console	void mReadMail();	//Shutdown the server	void mShutdownServer();	cMailServer();	~cMailServer();};


Next, The client, Which is the DLL in this case.

class cMailClient{private:	HANDLE vSlotHandle;	const char* vServerName;	DWORD vBytesWritten,vBytes2Write;public:	//Open the mailbox	void mOpenMailConnection();	//Write a letter	void mWriteMail(char mail[]);	//Shut it	void mCloseMailConnection();	cMailClient();	~cMailClient();};


I apologize for being so long winded, but this is a more logical method instead of Networking libs :).
-AnthonyG
cignox1
cignox1
Another way is to use shared memory, thought I wouldn't suggest it unless you really need it. In the case of the configuration tool, I would use a simple file. Fo something more complex, I would go with a tcp/ip connection or RPC (Remote Procedure Call)...
Ezbez
Ezbez
I think that programs such as IM clients are actually just one program with multiple windows. It's still the same 'program', so it doesn't need to communicate any differently than any other program. This lets them have the friends list, and separate chats open at once. If you open a couple chats in your favorite IM, then check the task manager, there's only one process running. You could certainly do this for what you described as an example.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.