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?

[Webinar] Streamline your web hosting managementRegister Today

NickRepinConnect With a Mentor Commented:
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.

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 :)
All Courses

From novice to tech pro — start learning today.