0% found this document useful (0 votes)
77 views4 pages

Project #1B - Chat Server

The document describes Project 1B which involves creating a chat server in C or C++. The server must listen for connections on a specified port and handle various message types from clients including login, list, sendto, and logout messages. It must support multiple simultaneous clients using select() and be robust to unexpected messages. The server will be graded based on passing functionality tests and avoiding memory leaks.

Uploaded by

Anjali Jain
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views4 pages

Project #1B - Chat Server

The document describes Project 1B which involves creating a chat server in C or C++. The server must listen for connections on a specified port and handle various message types from clients including login, list, sendto, and logout messages. It must support multiple simultaneous clients using select() and be robust to unexpected messages. The server will be graded based on passing functionality tests and avoiding memory leaks.

Uploaded by

Anjali Jain
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Project#1BChatServer

DueOct.20@11:59pm EE122:IntroductiontoCommunicationNetworks(Fall2008) DepartmentofElectricalEngineeringandComputerSciences CollegeofEngineering UniversityofCalifornia,Berkeley ProjectGoal Createthechatserverforthechatapplication.TheservermustbewritteninCorC++andmust usesockets.Itmustrunontheinstructionalmachines. Timeline ThesourcecodefortheserverisdueonOct.20.Thespecificationoftheclientandthe descriptionofthecheckpointwereprovidedinthepreviousdocument.

SectionI:Introduction
Thechatserverisresponsibleforprovidingamechanismfortheclientstocommunicate.This includesallowingclientstologinsotheycanbeidentifiedbyusernameandforwarding messagesfromoneclientdestinedtoanother.Thisalsoincludeslistingtheusernamesofthe clientsthatarecurrentlyloggedintofacilitatecommunication.

SectionII:ChatServerOverview
Thechatserverhastodothefollowingtasks: 1. Listenforincomingclientconnectionsataspecifiedport.Theserverobtainsthe portnumberfromacommandlineargument.Forexample: >./server10000 ThentheserverimmediatelyattemptstocreatethesocketusingTCPandtriesto listenforconnectionstothespecifiedportnumber.Ifitfails,theserverprintsan errormessagetotheconsoleandreturns.Toprinttheerrormessage,theserver mustcallfunctionperror()(definedinstdio.h)withthenameofthesocket functionthatfailedinlowercase.Forexample: perror(socket) Ifontheotherhand,theserverissuccessful,itcontinuestostep2. 2. Respondtomessagesreceivedbymultipleclients.Theservermustbeableto properlyrespondtothefollowingmessages: a. LoginMessage

b. ListMessage c. SendtoMessage d. LogoutMessage Thestructureofthesemessagesandtheactionstheservermusttakewhen receivingthemareprovidedinthefollowingsection.Additionally,theserver mustbeabletohandlemultipleclientssimultaneouslyusingselect().

SectionIII:RespondingtoMessages
Thefollowingisthestructureofthemessagestheserverreceivesfromtheclientandthe actionstheservermusttake.BisashortcutforByteandXBreferstoavariablelengthfield. Assumebigendiannumberrepresentationforthesemessages. Loginmessage: o Structureofmessage Fieldvalues: MSGTYPE:Setto0x01 UNAME:Loginusername o Actions IfUNAMEcontainswhitespace,ifitstartswithanullbyte,orifitis alreadytakenbyanotheruser,sendfailureresponse. Iftheclientwhosentthismessageisalreadyloggedin,alsosendfailure response. Otherwise,associatetheusernamewiththeconnectionandsendOK response o Structureofresponse Fieldvalues: MSGTYPE:Setto0x05 RESTYPE:Setto0x01forOK,0x02forMalformed,0x03for failure. ListMessage: o Structureofmessage Fieldvalues: MSGTYPE:Setto0x02 o Actions Fillresponsemessagewithusernameofeveryloggedinclient.

o Structureofresponse Fieldvalues MSGTYPE:Setto0x02 UNNUM:Settonumberofloggedinclients(thisvalueistreated asunsigned) UNAMES:Theusernamesoftheclientsthatareloggedin.Each usernameispaddedto20bytesasspecifiedintheprevious document. SendtoMessage: o Structureofmessage Fieldvalues:
MSGTYPE:Setto0x03. UNAME:Usernameofclienttowhomtoforwardthemessage. T LEN: Number of bytes in the text field (this value is treated as unsigned). TEXT:Messagesentbytheclient.Doesnothavetobenullterminated.

o Actions Inthefollowingexplanation,thismessagewasreceivedfromclientAand thetargetofthemessageisclientB. IfclientAisnotloggedinorcannotfindclientB(whoisspecifiedwith UNAME),sendfailureresponsetoclientA. Otherwise,replacethecontentsofUNAMEwithclientAsUNAMEand sendthemessagetoclientB.Ifthisfails,transmitafailureresponseto clientA. OtherwisesendOKresponsetoclientA. o Structureofresponse Fieldvalues: MSGTYPE:Setto0x05 RESTYPE:Setto0x01forOK,0x02forMalformed,0x03for failure. LogoutMessage: o Structureofmessage Fieldvalues:

MSGTYPE:Setto0x04

o Actions Ifclientisnotloggedin,sendfailureresponse.OtherwisesendOK response. o Structureofresponse Fieldvalues: MSGTYPE:Setto0x05 RESTYPE:Setto0x01forOK,0x02forMalformed,0x03for failure. AllOtherMessages: o Actions Sendresponseindicatingthatwehavereceivedmalformedpacket. Closeconnectionwithclient.

SectionIV:OtherRequirements
Yourservershouldberobusttounexpectedmessagesandshouldclosetheconnection withtheclientthatcausedthatmessageinsteadofcrashing.Otherclientsshouldnotbe affected. Thereshouldnotbeanymemoryleaks Theservershouldinteractproperlywiththeclientbinarythatwasbeenprovidedas partoftheclienttestscript.

SectionV:GradeBreakdown
95%Passingalltestcasesthattestthefunctionalityoftheserver(includingitsability toavoidcrashes). 5%Nothavinganymemoryleaks.Valgrindisagoodtoolforthis.

You might also like