Overview
To compile and link the files set your environment in the same way as you do to build OpenAMQ server and do the following:
$ c -l im_sender.c
Compiling im_sender...
Linking im_sender...
$ c -l im_receiver.c
Compiling im_receiver...
Linking im_receiver...
To run the whole thing, you have to start OpenAMQ server first:
$ amq_server
Once the server is running you can run chatroom window this way:
$ im_receiver <broker-address> <chatroom>
For example:
$ im_receiver localhost:5672 "OpenAMQ discussion"
To send messages to the chatroom, you have to run sender window this way:
$ im_sender <broker-address> <chatroom> <your-name>
For example:
$ im_sender 127.0.0.1:5672 "OpenAMQ discussion" "Baron Bartholomaeus von Saburg-Fridetzki"
There can be any number of clients connected to the same chatroom. There's no need to create chatrooms explicitly; these are created on demand.
License
BSD
Support
- Contact author for support.
Download
Following example uses single exchange ("amq.direct") to pass messages. Chatroom is identified by "routing key":
Following example uses separate exchanges of "fanout" type for individual chatrooms:
Comments
Edit | Files | Tags | Source | Print
Author
Martin Sustrik <moc.xitami|kirtsus#moc.xitami|kirtsus>
All examples
Simple file transfer: A simple file transfer application in C, an example of how to send and receive messages via OpenAMQ WireAPI.
Chatroom example: A simple instant messaging application in C, an example of how to send and receive messages via OpenAMQ WireAPI.
The im_sender.c program loops if you press Ctrl-C. It's trivial to fix; add these lines after the fgets statement:
The Ctrl-C won't break the program out of the fgets function call, but by checking if the connection has been killed, the program can exit properly when the user press Enter.
For more, see http://wiki.openamq.org/tutorial:handling-ctrl-c-in-applications.
Portfolio
Ok, the examples are fixed in the proposed way,
I've added im_sender2.c and im_receiver2.c to demonstrate how different exchanges can be used to pass different data flows (chatrooms) instead of using routing keys.
I usually dont take time to ever make comments on a web site but I have to say I would truly be doing you a grave disservice if I didnt write something. This post has most definitely opened my eyes. Thank you so much for writing it. autocouponcash