CS代考 python data structure Java COMP 3331/9331 – cscodehelp代写

COMP 3331/9331
Assignment T3 2021
Instant Messaging Application

All details are in the specification
• Information about deadlines, file names, submission instructions, marking guidelines, example interactions and various other specifics are in the specification
• Choice of programming languages: C, Java, Python (versions are noted in the specification)
• This talk provides a high-level overview

Two main components
• Server
• Always on
• Doesnotrememberstatefrompriorexecutions,onstart-upnoclientsareinitiallyactive • Responsiblefor
• User authentication
• Direct messages between clients (online or offline)
• Additional functions: presence notification, blacklisting, timeout inactive users
• Participates in setting up a p2p messaging session between two clients
• Implementsarequest/responseAPIforinteractingwithclient(s)
• Client
• Interactswithuserthroughcommandline
• Exchangesmessages(request/responseAPI)withtheservertomanifestthecommands
• Transport Protocol: TCP (required)
• You must design your own application layer protocol
• Thisincludesthesyntax/semanticsofthemessagesexchangedbetweentheclientandserver and the actions to be taken upon receiving each message

• Client and server executed on same machine
• Assume IP address of the other endpoint is (local host)
• Server
• Commandlinearguments:
• Server port (use a value greater than 1023 and less than 65536)
• Block duration in seconds (the duration for which a user is blocked after 3 unsuccessful login attempts)
• Timeout in seconds (the duration of inactivity after which a user is logged off)
• Executedfirst–waitsforclient(s)toconnect
• Client
• Commandlinearguments:
• Server port number (should match the first argument for the server)
• LettheOSpickananavailableport
• ClientshouldinitiateTCPconnectionwithserver(“”,serverport)
• Usershouldinteractwiththeclientthroughthecommandline(commandprompt,console)

Part 1: Client-Server Mode
• User Authentication
• Credentialsfilewillbeavailableincurrentworkingdirectoryofserverwithreadandwrite
permissions set (chmod +wr) – sample provided
• Askusertoenterusername(assumeusernameisincorrectformat)
• Ifusernameexistsandtheuserisnotalreadyloggedon(fromanotherclient),thenpromptuser for password
• If password matches, the user is assumed to be logged on
• If password doesn’t match, aske user to enter password again
• If a user successively fails three times, then they are blocked for the block duration – i.e., the user cannot login again for that time
• Ifusernamedoesn’texistprompttheuserforanewpassword
• Create a new entry in the credentials file (assume password is in correct format, no checks necessary)
• Presence Broadcast
• Whenauserlogson/off,displayamessagetoallonlineusersexcludingthosewhothisusermay
have blocked
• Detection of inactivity
• Ifauserdoesnotissueavalidcommand(client-serverorp2p)fortimeoutseconds,theyare assumed to be inactive and logged off

Part 1: Client-Server Mode
• message user
• Assume message is in the correct format (no checks are necessary)
• If user is online and has not blocked the sender, send the message
• If user is offline and has not blocked the sender, store the message for delivery when user logs on
• If user has blocked the sender or is invalid (i.e., username does not exist in the credentials file), then report an appropriate error message
• broadcast message
• Send message to all online users except those who have blocked the sender (in which case, report to sender that message could not be sent to some users)

Part 1: Client-Server Mode
• whoelse
• Displaynamesofalluserscurrentlyonlineexcludingthosewhohaveblockedtheuserexecutingthe
• whoelsesince time
• Displaynamesofalluserswhomayloggedinatanytimewithinthepasttimeexcludingthosewho
have blocked the user executing the command
• block user
• blocksuserfromsendingmessagestocommandissuer,receivepresencenotificationsabout
command issuer, and check online status (i.e.,whoelse, whoelsesince) about command issuer
• unblock user
• reverseofabove
• logout
• Logoutuserandsendpresencenotificationandcloseap2pmessagingsessionifactive
• Handle simple errors
• E.g.,invalidcommandsorblockinganinvaliduser,etc • Simpleerrormessagedisplayedtouser

Part 1: Client-Server Mode
• Server should support multiple clients
• All clients and server executing on same machine (
• Multi-threading
• Main thread waits for a new
TCP connection, creates the connection socket and spawns a child thread for interacting with one client
Client Process
Server Process
Welcoming, port X Socket
Connection, port X Socket 1
Connection, port X Socket 2
Client Socket
TCP handshake
Client Socket
Client Process

Part 2: Peer to Peer Messaging
• Setup process managed by server
• User A will initiate startprivate command with user B
• Server will check if user B has blocked User A
• Server will check with user B if they are willing to accept
• If OK to proceed, then certain information about B should be conveyed to A so that A can initiate a TCP connection with B
• Private user message
• Once p2p session is setup, the two users can message each other directly
bypassing the server
• Stop private
• Ends the p2p session
• Each user can be involved in at most one p2p session at any given time

Part 2: Peer to Peer Messaging
• Possible for user to move back and forth between client/server and p2p messaging commands
• Client needs to maintain a TCP connection with another client in addition to maintaining the TCP connection with the server
• Client also needs to interact with the user through command-line (even in client/server interactions) while also simultaneously interacting with the server and other client (in p2p messaging)
• Both above can be readily achieved via multi-threading. Alternately, you may explore non-blocking IO (select)

Data Structures
• Server must maintain certain state information including # of valid/online users, login times, blocked user lists, offline messages, etc.
• Proper design of data structures is essential to ensure all functionality can be achieved
• Be careful about accessing the data structures across multiple threads
• Avoid arbitrary upper limits for variables (e.g., no of users) • Dynamic memory allocation is recommended

How to start?
• How to get started
• Start with a server supports only one client at a time
• Add user authentication
• Extend server to support multiple client
• Add presence notification
• Add messaging (1 to 1, broadcast, offline)
• Add inactivity detection
• Add support for checking online (+history) queries • Add blocking
• Next move to p2p messaging

Messages displayed to users
• Use meaningful text
• Does NOT have to match the examples in the specification • Assignment will be MANUALLY marked by your tutors
• No messages at the server

• Program design
• Data structures
• Details of the application layer protocol
• Trade-offs considered
• Point out issues if program does not work under certain circumstances
• Refer to all borrowed code

• Test, Test, Test
• Server and client(s) executing on same machine
• Emphasis on correct behaviour
• Basic error checking
• MUST test In VLAB environment and through command line
• If we cannot run your code, then we cannot award you any marks • Detailed marking rubric is available in specification

• Both parties involved are considered guilty
• If posting code on online repositories, then ensure access is private
• If caught
• You will receive zero marks (and there may be further repercussions if this is
not your first offence)
• Your name will be added to the school plagiarism register
• Every term I have had to do the above for a small group of students • Would be nice to not have to do it in this term

Non-CSE Students
• Must be enrolled in a non-CSE program (double degree that includes a CSE major does not qualify)
• Can opt for non-CSE option
• MUST request permission to do so by 5pm, 15th October by emailing

• Many program snippets are on the web page • Including multi-threading code snippets
• Your socket programming experience in Labs 2 and 3 will be useful • Repository of resources is here

Seeking Help
• Assignment specific consults (for all 3 programming languages) from Weeks 7-10
• Schedule to be announced in a few days • Course message forum
• Read posts from other students before posting your question • Read the spec – very often your answer will be in there

Leave a Reply

Your email address will not be published. Required fields are marked *