I'm creating a server application that needs to broadcast a message to several clients. I figure that mailslots is the way to go, but how do I create them?

I can get a communication going between two mailslots, but it depends on the order I start the applications. If I start the server first, all the clients get the correct mailslot handle, but doesn't receive messages written to that mailslot. If I start the clients first they can't get the handle, since it's not created by the server.

If I use CreateMailSlot on both client and server machines and start the client first I can send messages from the server to the client.

I guess that what I'm asking is: Does anyone have some examples of how to create these mailslots. I think my problem is that I use wrong parameters in (such as FILE_FLAG_OVERLAPPED, etc) in WriteFile, CreateFile and CreateMailSlot...

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mailslot is a one-way mechanism. Only process created mailslot can read from it.

For example, if you CreateMailslot() on the server, and CreateFile("mailsot name") on the clients, all clients can only write to that mailslot, but not read from them. Server can only read, but not write.

If you wish to broadcast messages from the server to the client, you have to CreateMailslot("same name for all") on each client machine.

Then you can use To put a message into every mailslot with a given name in the system's primary domain, use CreateFile("\\*\mailslot\name") on the server to broadcast messages to all client mailslots.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I made a wrong paste from MSDN to the last sentence, but I hope it's clear enough.

To find examples, just open MSDN library (if you have MS Visual C) and choose the Platform SDK->Windows base services->Interprocess communications->Mailslots->Using mailslots.

Or select Search tab and search for CreateMailslot().

carceriAuthor Commented:
Thanks, now it works just as I intended :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.