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.
/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. You program will be peer-to-peer, that is you will only write ONE program, and run multiple instances 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 (something above 5000). 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 search for chat partners.
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 routine at the same time. The idea is that 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: Feature | Required | CS II![]() |
Soft Dev | Op Sys |
---|---|---|---|---|
Well commented code | yes | 5 | 5 | 5 |
On startup ask user for name to broadcast | yes | 5 | 5 | 5 |
Well Designed/Written Code | yes | 20 | 20 | 20 |
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 |
Display "Typing" if other user typing | not with next | 20 | 15 | 15 |
Character at a time transmission/reception (see characters as typed | not with prev | 20 | 15 | 15 |
Synchronous two-way chat function (take turns typing) | Must do this or next | 30 | 25 | 15 |
Display new possible partners as they appear (asynchronous) | 30 | 20 | 15 | |
N-way chat. Allow used to bring in multiple partners in a group chat | 35 | 30 | 25 | |
Asynchronous two-way chat function (Either side can type any time, asynchronous, requires threads) | Must do this or previous | 50 | 40 | 30 |
MAXIMUM SCORE | 185 | 160 | 135 |