Beruflich Dokumente
Kultur Dokumente
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
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.