mfc >> How to send messages between 2 applications on 2 computers?

by Bob Moore » Tue, 27 Apr 2004 02:10:22 GMT

On Mon, 26 Apr 2004 14:23:42 +0430, "Behzad" <behzadvc AT , Yahoo Dott
Com> wrote:

> Is there
>someway to send messages between applications running on 2 computers? I do
>not mean a client/server program, something similar to PostMessage but
>between 2 aplications on 2 computers.

Further to Scott's (entirely correct) posting...

This is snipped from my website article on IPC, at
http://bobmoore.mvps.org/Win32/framed_tip009.htm
The layout on the web site makes it easier to read, but that article
also covers IPC within a single computer, which I've omitted here.

************

Named Pipes
-----------
Use file APIs, so relatively simple to implement if you're at all
file-savvy. Not queued. Connection-oriented, i.e. point to point, and
therefore can't broadcast. Win9x can act as a named pipe client, but
not as a named pipe server. NT can do both.

Mailslots
---------
Queued, connectionless and can therefore broadcast. Simple to use, but
have some drawbacks :

1. Because the sender doesn't know what protocols are installed on the
receiver, mailslot messages are duplicated on every installed
protocol, and it's your responsibility to sort out the resulting mess
(usually with some sort of tagging system).

2. A length limit of 400 bytes or so.

3. Don't have guaranteed delivery, though I've yet to see one fail to
arrive (on a LAN : see point 4).

4. Broadcasting to a group (e.g. a domain) works fine... until you
want to do it outwards over a RAS link. Then it just plain breaks. You
won't find this fact documented anywhere, as far as I can find. But it
bit me, it bit Intel, and it will bite you as well. Microsoft
explained this blocking behaviour to me as their desire not to flood
another network with broadcast UDP, which is fair enough... if they'd
actually got it right. In actuality, about one message in 6 gets
through.

Sockets
-------
Microsoft's Winsock is based upon the Berkeley Unix sockets
implementation, with proprietary (naturally, this is Microsoft)
extensions. Those extensions include support for asynchronous socket
calls. Sockets have the advantage of simplicity and portability for
heterogeneous environments. If you are working with Internet-aware
applications, sockets are your IPC of choice.

There are two types of sockets, stream (TCP) and datagram (UDP). TCP
is point to point and offers guaranteed in-order delivery. UDP
supports broadcast, is size-limited and offers none of the above. Note
that stream sockets by their very nature do not support framing : one
of your messages may be split across two or more packets, so your
protocol must take account of this (i.e. one receive notification !=
one whole message).

Under Windows, there are various implementation techniques available
to you.

1 Synchronous Sockets
Basically, using worker threads and blocking socket calls. This is
simple to implement, but doesn't scale at all well.

2 Asynchronous : Overlapped I/O
Finicky to code, and doesn't really offer any advantage over the
next two methods.

3 Asynchronous : windows-message notification (a.k.a. the
WSAAsyncSelect method)
Using the function WSAAsyncSelect, you specify that you want to
receive notifications of socket events via the windows message queue.
Upon receipt of the event, calling a specified function resets the
notification ready for the next event. If you have a GUI app and
maximal throughput isn't a necessity, this is a good bet.

4 Asynchronous : I/O Completion Ports
In this technique events are queued through an I/O completion port,
so it combines the convenient queueing of the WSAAsyncSelect method
with the performance of overlapped I/O. For non-GUI apps, or those
that require extreme throughput, this is a good bet. Quality sample
code is also available from www.mvps.org !

Note - Winsock 2.0 supports socket communications over protocols other
than TCP/IP.



--
Bob Moore [WinSDK MVP]
http://bobmoore.mvps.org/
(this is a non-commercial site and does not accept advertising)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Do not reply via email unless specifically requested to do so.
Unsolicited email is NOT welcome and will go unanswered.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Similar Threads

1. How to send messages between 2 applications on 2 computers?

2. Send messages to other computer?

Dear all,

  I would like to know how can I send some messages to other computers in
the intranet so that other computer can suddenly show the messages in the
pop up window?  Thank you for all of your help.

Alex


3. sending message to app on other computer - CSharp/C#

4. Single Application Instance Forcing, and subsequent message sending

Hi,

I have found the code below to detect if a process is already running. This 
seems to work well, but then how do you sent the main program class in 
process 1 messages about the command parameter info of process 2.

Thanks,
Jon

private static Process RunningInstance()

{

Process current = Process.GetCurrentProcess();

Process[] processes = Process.GetProcessesByName (current.ProcessName);

//Loop through the running processes in with the same name

foreach (Process process in processes)

{

//Ignore the current process

if (process.Id != current.Id)

{

//Make sure that the process is running from the exe file.

if (Assembly.GetExecutingAssembly().Location.

Replace("/", "\\") == current.MainModule.FileName)


{

//Return the other process instance.

return process;


}

}

}

//No other instance was found, return null.

return null;

}


5. Send a message to a Single Instance Application - CSharp/C#

6. Send Message to Button control in a PB Application

Hi,

I am trying to send message (WM_CLICK) to a button control in a
PowerBuilder application using a C# spy program.  This works for all
other windows applications but in case of PB application it does not
work.

Would appreciate any help on this.

Thanks in advance

Raj

7. Sending Window Messages from an MFC app to a Windows Firm tray application

8. How to send message to other application through ur program

hello friends,
I am new to MFC and Want to send messages to Notepad.i want full
control over notepad . iam woking with window xp platform and using
vc++6.so tell me how can i do that .try to explain if want the whole
code for that.