lab2 - CSE 422 Lab 2: Creating a Multi-Threaded Chat Room...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 422 Lab 2: Creating a Multi-Threaded Chat Room Server In this lab you will be making a server application for a chat room. You will need to use threading to listen for a client’s message, as well as wait for any number of clients to connect. We will give an introduction of the Pthread library for this lab. Along with threading, you will also have to use a mutex lock to maintain stability of the list of clients. We have supplied a code skeleton for the server application, including the locking and unlocking of the mutex. We have also supplied the client application source code for you to use, but you should not alter that code, because you will not be turning it in; your server will need to work with the client, as is. The application created will be named chat , which takes as arguments the server hostname and a UDP port, as in the client program in Lab 1. The server is name chat_server and takes no command line arguments. You will need to download:,, lab2_packet.h, and the makefile. These files will compile, but the server will not do anything useful. Overview of the Chat Room Application: The application will be able to allow multiple clients to connect at one time. It will maintain a list of the clients connected at any time. Messages sent by a client will be received by the server and broadcasted to all the clients. Clients are allowed to come and go as they wish, and so the server must be able to handle the clients leaving properly. Clients are also able to check who is online at any time. If the server is called to shutdown, it will inform the clients before closing it's connection and terminating the application. Pthread Library Introduction: Here is a man page for pthread class: The four functions that you will have to use are: pthread_create(), pthread_detach(), pthread_mutex_lock(), pthread_mutex_unlock(). You will also have to use the pthread_t and pthread_mutex_t classes. int pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *); The first parameter must be a non null pointer to a pthread_t object. The second is a set of attributes to be used and for this project you should use NULL to set the default values. The last two parameters are the function to be called followed by the argument to be passed to the function. If you notice they are void parameters, so you will need to use type casting to pass values to your threaded function. Also, if you want to pass more than one parameter to the threaded function, you should create a struct
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

lab2 - CSE 422 Lab 2: Creating a Multi-Threaded Chat Room...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online