This library was developed to add compatibility with a C# program for my old project, written in C++ using mailslots.
Introduction
The purpose of creating MSConnectionCS
DLL using mailslots is to minimize the efforts of the programmer for developing C# applications.
It was necessary to add compatibility with a C# program for my old project, written in C++ using mailslots, so there was a need to develop this library.
In contrast with the following articles...
...this library does not use unsafe code, has separated classes for client and server and transmits not only string messages but also structures.
A Mailslot is a one-way interprocess communication mechanism, available on the Microsoft Windows operating system, that allows communication between processes both locally and over a network (https://en.wikipedia.org/wiki/Mailslot).
MSConnectionCS
DLL includes the following classes:
Field msg_id
is filled by User for identification transmitted message on server side, each message is described in its structure (see file UserStructures.cs in download source files).
Field RandomId
is filled automatically and used to throw away repeated messages in case of transmitting messages between computers, because Mailslot mechanism transmits data using several protocols. I received two messages in my demo, but if to turn off access resources on a Microsoft network, only one message transmits.
Run ncpa.cpl:
Block Diagrams MSConnectionCS DLL
Transmit messages between processes in one computer (ConnectionMode = SAME_COMPUTER
):
Transmit messages between computers (ConnectionMode = OTHER_COMPUTER
):
Creation Server
server = new MSConnectionServerTest();
bool ret = server.BuildServer(MailslotName, (int)numberOfMessages, mode);
if (ret == false)
{
Console.WriteLine("Server Creation error!");
Environment.Exit(0);
}
while (true)
{
string word = Console.ReadLine();
if (word == "exit")
{
server.Dispose();
Environment.Exit(0);
}
}
Creation Client
client = new MSConnectionCS.MSConnectionClient();
client.BuildClient(server_address, Name, client_name, mode);
Demo Parameters and Running
usage: mscon /wm:server|client|debug /cm:0|1 /print:0|1 /nmsg:number
/msname:<mailslot name>
/cname:<client name>
/scomp:<server comp.name>
/scompip:<server comp.ip>
/wm - workmode
/cm - connection mode 1 - different computers or
0 -same computer (by default 1)
/print - write(1) or not write(0) on console debug information (by default 1)
/nmsg - numberOfMessages in MailSlot queue - only for /cm = 0
(by default = 10)
/msname - server_name by default = server
/cname - client_name < 19 symbols
/scomp - server computer name (if server computer name != "." /cm = 1
/scompip - server computer id (if server computer ip is set - /cm = 1
Run console application demo mscon.exe twice:
mscon /wm:server /msname:myserver
mscon /wm:client /msname:myserver
or once:
mscon /wm:debug /msname:myserver<br>
other examples:
mscon /wm:debug /msname:myserver /scomp:DESKTOP_OK
mscon /wm:debug /msname:myserver /scompip:10.0.0.14
Conclusion
If your server application must receive messages from multiple clients, Mailslot Inter-process Communication is a good decision. But do not forget that size of message cannot be larger than 424 bytes when sent between computers. If size of message is larger, you can fragment it and use client name and client computer name in CONNECT_HEADER
, but MSConnection
DLL does not support this feature.
History
- 5th August, 2020: Initial version