example/C/Makefile.am
noinst_PROGRAMS = mulclient$(EXEEXT) mulserver$(EXEEXT) manfilter$(EXEEXT) \
testclient$(EXEEXT) testserver$(EXEEXT) \
MyClient$(EXEEXT) MyServer$(EXEEXT) \
Filter1$(EXEEXT) Filter2$(EXEEXT)
MyClient_SOURCES = MyClient.c MyClient_LDADD = -lm ../../src/*.lo MyServer_SOURCES = MyServer.c MyServer_LDADD = -lm ../../src/*.lo
INCLUDES = -I$(srcdir)/../../src
win.example/C/MyServer.c
#include "string.h" #include "msgque.h" static enum MqErrorE MyFirstService (struct MqS *ctx, MQ_PTR data) { MqSendSTART(ctx); MqSendC(ctx, "Hello World"); return MqSendRETURN(ctx); } static enum MqErrorE ServerSetup (struct MqS *ctx, MQ_PTR data) { return MqServiceCreate(ctx,"HLWO", MyFirstService, NULL, NULL); } int main (int argc, MQ_CST argv[]) { struct MqBufferLS * largv = MqBufferLCreateArgs(argc, argv); struct MqS * ctx = MqContextCreate(0, NULL); MqConfigSetName (ctx, "MyServer"); MqConfigSetServerSetup (ctx, ServerSetup, NULL, NULL, NULL); MqConfigSetDefaultFactory (ctx); MqErrorCheck (MqLinkCreate (ctx, &largv)); MqErrorCheck (MqCheckForLeftOverArguments(ctx, &largv)); MqErrorCheck (MqProcessEvent(ctx,MQ_TIMEOUT,MQ_WAIT_FOREVER)); error: MqExit(ctx); }
The server is started as network visible TCP server listen on PORT 2345 using a THREAD for every new connection request:
> MyServer --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:
> MyServer --uds --file /path/to/any/file.uds --thread
Three things are important:
Services are created with the MqServiceCreate(ctx,token,fService,data,fFree) 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 struct MqS*. 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 struct MqS* object class, the both statements SendSTART() and ctx.sendSTART() are identical.
#include "string.h" #include "msgque.h" int main (int argc, MQ_CST argv[]) { struct MqBufferLS * largv = MqBufferLCreateArgs(argc, argv); struct MqS * ctx = MqContextCreate(0, NULL); MQ_CST c; MqConfigSetName(ctx, "MyClient"); MqErrorCheck (MqLinkCreate (ctx, &largv)); MqErrorCheck (MqCheckForLeftOverArguments(ctx, &largv)); MqSendSTART(ctx); MqSendEND_AND_WAIT(ctx, "HLWO", 10); MqErrorCheck (MqReadC(ctx, &c)); printf("%s\n", c); error: MqExit(ctx); }
To call a network visible TCP server listen on PORT 2345 use:
> MyClient --tcp --port 2345 > Hello World
To call a network visible UDP server listen on FILE /path/to/any/file.uds use:
> MyClient --udp --file /path/to/any/file.uds > Hello World
To call a local server started by the client using PIPE communication use:
> MyClient @ MyServer > Hello World
1.5.8