create new tag
, view all tags

Peer to Peer Chat


The objective of this project is to gain insight into the challenges of data communications within a wireless environment. To achieve this, you will implement a "peer-to-peer chat application" over a wireless communication channel that will exchange messages between your Monash packet radio board and other students' boards within your board's transmission range.


Chat Block Diagram

You need to do the following:

  • Write the required OMNeT++ modules MediaAccessControl, ChatSend, and ChatRcv that use the SmartPacketRadio module and conform to the specifications outlined in the subsequent sections which is capable of communicating (via the shared wireless medium) with other students' Chat applications to exchange messages.
  • You need make sure that your code should be easily understood by anyone encountering it for the first time. Code should be extensively commented and include block comments describing the purposed of code sections.

Media Access Control (MAC)


The MAC protocol for the Chat application will be extremely simple. We will create a more realistic one in the next assignment "Reliable File Transfer". The sending operation will involve only one step:

  • Send data when it is ready (that is, when a message is received from the ChatSend module).
The receiver RxNode and sender TxNode addresses are 1-byte long Monash packet radio addresses. Your own radio address could be obtained by using the following statement:
   static_cast<SmartPacketRadio *>(cSimulation::getActiveSimulation()->getModuleByPath("radio"))->getAddress();
Note that addresses are sent as binary numbers, not as ASCII character sequences. The address 0xFF is the broadcast address. In this assignment, you will not need to calculate the CRC field values, just use 0xFF.

Monash Packet Radio Network frame format


When a frame is received, the MAC sublayer should

  1. check that the frame is either broadcast or destination address matches to your radio, if yes
  2. deliver the message contents to ChatRcv.


ChatSend module should send a message to MAC whenever the user has finished typing and pressed the "Enter" key. The message entered by the user will be in this format: XXX message (where XXX is either the broadcast or recipient's address). You will need to use the following in the initialize() module

   static_cast<PollScheduler *> (cSimulation::getActiveSimulation()->getScheduler())->registerFD(this, STDIN_FILENO);
   fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO,F_GETFL)|O_NONBLOCK);    // sets the stdin in non-blocking mode so that frames can still be received. 

Whenever there is input to be read from stdin (i.e. by default, keyboard), the module will receive a message with name ready to read. Also remember to add

   #include <unistd.h>
   #include <fcntl.h> 
to use the fcntl() system call.

Then, in the handleMessage() of ChatSend, the typed message can be obtained like the following:

  if (msg->isName("ready to read")) {
     bytes_read = read(STDIN_FILENO, buffer, n); // check manual page of read() for details: "man read".


Whenever a message is delivered by the MAC module, ChatReceive should display the message in this format:

   YYY <message>
where YYY is the sender's address.


You can work on your assignments and debug the code on your own time without accessing to a Monash packet radio board. Here is the trick.

Topic revision: r12 - 2013-09-19 - AhmetSekercioglu
This site is powered by the TWiki collaboration platformCopyright © 2008-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback