example/C#/Makefile.am
RULE_CS_EXE = $(CSCOMP) -v -nologo $(CSHARP_DEBUG) -reference:../../csmsgque/csmsgque.dll -out:$@ -target:exe "$<"
MyServer.exe: $(srcdir)/MyServer.cs ../../csmsgque/csmsgque.dll
$(RULE_CS_EXE)
MyClient.exe: $(srcdir)/MyClient.cs ../../csmsgque/csmsgque.dll
$(RULE_CS_EXE)
win.example/C#/MyServer.cs
using System; using csmsgque; namespace example { sealed class MyServer : MqS, IServerSetup, IFactory { // create new intances MqS IFactory.Call() { return new MyServer(); } // service to serve all incomming requests for token "HLWO" public void MyFirstService () { SendSTART(); SendC("Hello World"); SendRETURN(); } // define a service as link between the token "HLWO" and the callback "MyFirstService" void IServerSetup.Call() { ServiceCreate("HLWO", MyFirstService); } static void Main(string[] argv) { MyServer srv = new MyServer(); try { srv.LinkCreate(argv); srv.ProcessEvent(MqS.WAIT.FOREVER); } catch (Exception ex) { srv.ErrorSet (ex); } srv.Exit(); } } }
The server is started as network visible TCP server listen on PORT 2345 using a THREAD for every new connection request:
> mono MyServer.exe --tcp --port 2345 --thread
If you are using UNIX and if you want to setup a high-performance local server then use the build-in UDS (Unix-Domain-Sockets) capability to listen on the FILE /path/to/any/file.uds instead on a network port:
> mono MyServer.exe --uds --file /path/to/any/file.uds --thread
Three things are important:
Services are created with the ctx.ServiceCreate(string token, IService service) function. The first parameter is a 4 byte Token as public name. 4 byte is required because this string is mapped to a 4 byte integer for speed reason. The second parameter is an object providing the SERVICE CALLBACK interface.
The SERVICE CALLBACK function has one parameter of type MqS ctx. This parameter refer to the original object (in our case MyServer). If the service object (in our case MyFirstService) is a subclass of the original MqS ctx object class, the both statements SendSTART() and ctx.sendSTART() are identical.
using System; using csmsgque; namespace example { sealed class MyClient : MqS { static void Main(string[] argv) { MyClient c = new MyClient(); try { c.LinkCreate(argv); c.SendSTART(); c.SendEND_AND_WAIT("HLWO", 5); Console.WriteLine(c.ReadC()); } catch (Exception ex) { c.ErrorSet (ex); } c.Exit(); } } }
To call a network visible TCP server listen on PORT 2345 use:
> mono MyClient.exe --tcp --port 2345 > Hello World
To call a network visible UDP server listen on FILE /path/to/any/file.uds use:
> mono MyClient.exe --udp --file /path/to/any/file.uds > Hello World
To call a local server started by the client using PIPE communication use:
> mono MyClient.exe @ mono MyServer.exe > Hello World
1.5.8