CS332, Spring 2016: TCP Chat Client and Server

advertisement
CS332,Spring2016:TCPChatClientandServer
Forthisassignment,youneedtowriteachatsystemthatwillallowmultipleusers
tochatinteractivelyinaTerminalwindow.Oneserverwillberunningona
designatedport,andanynumberofclientscanconnectandtalktoeachother
interactively.
Herearesomescreenshotswhen2clientshaveconnectedtotheserver.
Thebasicfunctionalityisthis:
• Yourclientreadsoptionsfromthecommandline(seebelow).
• Yourclientconnectstotheserver.
• Yourclientcontinuouslyreadsfromstdinandfromtheserversocket.
o Ifitgetsdatafromstdin,itprepends<Yourname>says:tothetextand
sendsittotheserver.
o Ifitgetsdatafromthesocket,itprintsittostdoutandflushesstdout.
Youmayimplementthisinpython,C,orC++.I’vedoneitinpythonbecauseitis
cleanandneatandIloveit.
Youmustimplementthesecommand-linearguments:
Name(s)
Option
Meaning
Defaultvalue(if
optionnotgiven)
-v,--verbose
Turnonverbose
False
printingtohelp
debugging
-s,--server
ServernameorIP Themachinethe
127.0.0.1(i.e.,
address
serverisrunning
localhost–this
on
machine)
-p,--port
Portnumber
TheTCPportthe
12345
serverislistening
on.
-n,--name
Astring
Thenamebywhich Yourmachine
youareidentified name.
toothers.
Whenverboseisturnedon,yourclientshouldprintoutenoughinformationtohelp
youfigureoutwhatyourprogramisdoing.E.g.,myclientprintsoutamessage
wheneveritgetssomethingfromstdinorthesocketandwheneveritsends
somethingoutstdinorthesocket.
ImplementationNotes
YourmainloopisawhileTrue:loopandthefirstthingyoudoinsidethere
(typically)isacalltoselect().Theselect()callhasstdinandtheserversocketinthe
listyouarewaitingtoreadfrom.
Yourcodeshouldhandleerrorsgracefully.I.e.,ifasystemcallreturnsanerror,you
shouldprintoutausefulmessageandexitgracefully.Theusershouldnotseeacore
dumporastacktraceprintedout.Youmusthandlethecasewheretheservergoes
downwhenyourclientisstillconnected.
Youwillfindthefirstlinesofthetalk_client.pyfilein
/home/cs/332/sp2016/chat/folder.
Mytalk_server.pycfileisin/home/cs/332/sp2016/chat.Runitwith–h
optiontoseewhatthecommand-lineoptionsareforit.Runningitwith–vis
especiallyuseful.Youwillneedtoruntheserverbeforeyoucanlegitimatelytest
yourclient.
Youexityourtalk_client(andthetalk_server)bydoingCtrl-Cintheterminal
windowinwhichitisrunning.
Thereareatonofimplementationsofthisonline.Foryourownlearning
experience,donotcopyandpastecodefromthem.Ifyouhavetolookuphowto
useselect(),e.g.,you’llprobablyseeanimplementationoftheclientorserver…Try
toimplementasmuchasyoucanwithoutcopyingcodefromonline.Youmustcite
everyplacewhereyoufindcodethatyoucopyintoyourcode.
ThoseDoingtheClassforHonorsorWanttodosomethingreallycool
Thereisnothingthatmustbedoneforhonorsstudentsthistime,buttherewillbe
plentywhenweimplementthetalk_server.py.
Thosewhowanttomakeareallynicesystemcouldconsiderthis:
• Usecursestodisplayeachchatter’slinesinadifferentcolor.
• Usecursestosplitthewindowintotwoparts:youtypeinonehalfandall
theothers’outputgoesintotheotherhalf.
GradingRubric:20ptstotal
• 15pointsforcorrectness.
o Operatescorrectly:8
o Handlescommand-lineoptionscorrectly:4
o Handleserrorconditionscorrectly:3
• 5pointsforclean,well-indented,well-documentedcode.
Don’tforgettoputyourname,date,etc.,inacommentatthetopofyourfile(s).
Submitbycopyingto/home/cs/332/current/<yourid>/chat/.
Download