{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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_server.cc, lab2_client.cc, 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: http://opengroup.org/onlinepubs/007908799/xsh/pthread.h.html 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.
Image of page 1

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern