Getting started with the MQTT client for C
Get up and running with the sample MQTT client for C on any platform on which you can compile the C source. Verify that you can run the sample MQTT client for C with either IBM® MessageSight or IBM WebSphere® MQ as the MQTT server.
Before you begin
- If there is a firewall between your client and the server, check that it does not block MQTT traffic.
- For the supported and reference MQTT client for C platforms. See System requirements for IBM Mobile Messaging and M2M Client Pack.
About this task
Follow this task to compile and run the sample MQTT client for C on Windows from the command line or from Microsoft Visual Studio 2010. Microsoft Visual Studio 2010 is also used to compile the client in the command-line example. Modify the command-line scripts to compile and run the sample on other platforms.
Procedure
Compile and run the MQTT client sample C app from the command line
Compile and run the MQTT client sample C app from the command line. The sample is in the MQTT SDK. It demonstrates an MQTT publisher and subscriber.
Before you begin
Install a C development environment; for example the Microsoft Visual Studio 2010 as used in the example.
About this task
Compile and run the C sample, MQTTV3Sample, in the SDK clients subdirectory, sdkroot\SDK\clients\c\samples.
Procedure
The following script compiles and runs the sample on a Windows 32-bit platform, built with Microsoft Visual Studio 2010. Run the script from the sdkroot\SDK\clients\c\samples subdirectory.
@echo off
setlocal
call "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
cl /nologo /D "WIN32" /I "..\include" "MQTTV3Sample.c" /link /nologo ..\windows_ia32\mqttv3c.lib
set path=%path%;..\windows_ia32;
start "MQTT Subscriber" MQTTV3Sample -a subscribe -b localhost -p 1883
@rem Sleep for 2 seconds
ping -n 2 127.0.0.1 > NUL 2>&1
MQTTV3Sample -b localhost -p 1883
pause
endlocal
Results
Compile and run the MQTT client sample C app from Microsoft Visual Studio
Compile and run the MQTT client sample C app from the Microsoft Visual Studio. The sample is in the Mobile Messaging and M2M Client Pack. It demonstrates an MQTT publisher and subscriber.
Before you begin
The example uses Microsoft Visual Studio 2010. You can use other C development environments on Windows and other platforms; for example Eclipse IDE for C/C++ Developers.
About this task
Procedure
Results
What to do next
Build and run the asynchronous publisher and subscriber. The examples are MQTTV3ASample.c and MQTTV3ASSample.c in sdkroot\SDK\clients\c\samples.