Lab 2/3/4 CS Majors

This lab has three parts, called Lab 2, Lab 3 & Lab 4, in order to correlate with more closely with the CSNE labs (and thus reduce confusion)

UDP Programming in C++

Lab Objective:

  • To gain experience using Unix/Linux UDP socket programming. You will be writting a UDP peer-to-peer chat program. This program will NOT have a server, it will make connections directly between two clients. Upon running the program, it will "search" for partners, and list them for the user. If no partners are available, it will continue to search until one (or more) is found. Once a partner is selected, the program will then allow the two clients to type messages to each other. There are enhancemens beyond this which you may choose.

Reading/Reference: Lab overview:

You will create programs using UDP to perform general chat sessions. You can use the code in /home/class/CSC4093/UDBChat/ and /home/class/CSC4093/BroadcastUDP/ as a starting point, but do not simply hack the code to achieve functionality. I will expect you to create a set of useful, reusable, network functions using sockets, and then to create well designed, structured code to achieve the required functionality.

Below first is the simple code from the first lab. This project is client/server oriented. Your program will be peer-to-peer, that is you will only write ONE program, and run multiple instances of that program to talk to each other.

The user will NOT enter IP addresses or port numbers - this aspect is hidden from the user. Rather each program will start up and broadcast packets announcing it's presence on a single port you choose (use 5000 if you want it to get thorugh the campus firewall!). It will also listen on the same port, and build a list of partners it discovers. The user can than select a partner, or accept a request from another partner, and enter into a two way chat with that partner. If one partner terminates the chat by typing $exit, both sides will resume their search for chat partners.

Broadcast.png Chat.png

A tricky aspect of this project is that once you start waiting for a packet on a port, the program waits until it gets a packet, blocked. There is a solution - threads. The idea of threads is that the program is running multiple code streams at the same time. Thus you can have a thread broadcasting beacons, another listening for beacon, one waiting for packets from a chat partner(s), and one waiting for user input. You can start all these threads, and than have them communicate through shared data structures in the program. Be careful, however, of race conditions.

Sample code for UDP Programming on Linux: (in "/home/class/csc4093/UDPChat")

Sample code for broadcasting: (in "/home/class/csc4093/UDPChat") Sample code for creating threads: (in "/home/class/csc4093/ThreadExample") Sample code for sending and receiving broadcasts in multiple threads (in "/home/class/csc4093/ThreadBroadcast") Thread Synchronization

The threads library provides three synchronization mechanisms:

  • mutexes - Mutual exclusion lock: Block access to variables by other threads. This enforces exclusive access by a thread to a variable or set of variables.
  • joins - Make a thread wait till others are complete (terminated).
  • condition variables - data type pthread_cond_t
Sample code for sending and receiving broadcasts in multiple threads with mutex for synchronization (in "/home/class/csc4093/ThreadBroadcastSync")

Lab tasks:

The lab is worth 100 points total. Below I give you a set of requirements and options. You may do as many or few – there is a chance to get extra credit. However, no matter what you do, you will not get higher then a 100 if you do not have good clean code. Your score is dependent on the highest level of CS course you have taken.

In general, if you want to do more than one thing at a time, threads are required, this is asynchronous interaction. The more simple approach is synchronous, where only one thig happens at a time, and one side must wait for the other.

Feature Required CS II Soft Dev Op Sys
Well Designed/Written Code yes 20 20 20
Well commented code yes 5 5 5
On startup ask user for name to broadcast yes 5 5 5
Transmit at least one beacon on startup ( synchronous) yes 20 15 10
Wait for a partner beacon - Show name and allow user to connect and chat, or wait for next beacon ( synchronous) yes 20 15 10
Synchronous two-way chat function (take turns typing, synchronous) Must do this or next 30 25 20
Asynchronous two-way chat function (Either side can type any time, asynchronous, requires threads) Must do this or previous 50 40 35
Display new possible partners as they appear ( asynchronous)   30 20 15
N-way chat. Multiple users are all chatting together.   35 30 25
MAXIMUM SCORE   185 160 135

Due Dates

  1. Lab 2: Sept 24 midnight: At least 30 points work from above.
  2. Lab 3: Oct 1 midnight: At least 60 points work from above.
  3. Lab 4: Oct 8 midnight: At least 100 points work from above.

Turn in (for each)

  1. A document listing the features you support
  2. Screen captures clearly (with headings) demonstrating each feature support above.
  3. All source code (including makefile, or zips project if you used Netbeans)
-- JimSkon - 2011-09-15
Topic attachments
I Attachment Action Size Date Who Comment
Pngpng Broadcast.png manage 20.1 K 2015-09-16 - 15:31 JimSkon  
Pngpng Chat.png manage 16.2 K 2015-09-16 - 15:31 JimSkon  
Topic revision: r6 - 2015-10-06 - JimSkon
 
This site is powered by the TWiki collaboration platformCopyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback