Project 2 - many-to-many Chatroom

How to run my program?

compile

  • use makefile
make

image

execution

  • bulid a server
./server

image

  • build a client
./client [username] 127.0.0.x

image

result

(1) Kevin and Amy connect to the server

image

(2) Kevin says "hello~Amy"

image

(3) Amy will receive the message

image

(4) Amy responses "hi~Kevin!"

image

(5) Kevin will receive the respond

image

(6) server receives all the messages

image

  • this chatroom accommodates max to 10 clients

Briefly describe the workflow and architecture of the system

  • architecture

image

  • workflow

image

Explain the solution of synchronization problems in this project

synchronization problems :

message in shared memory might be changed by new message while not all the clients receive the old message

sem_wait(&mutex); //semaphore wait
while(change); // wait until all the threads receive the message, then we can change the content in shared memory
"critical section"
change=1;
sem_post(&mutex); //semaphore signal
  • mutual exclusive : only one thread (client) can change the message content in shared memory at one time
  • progress : thread can access to shared momory if all the clients receive the old message (change=0)
  • bounded waiting

Discuss anything as possible

(1) user interface

(2) have read notice

(3) record chatting history