CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4...
Transcript of CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4...
![Page 2: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/2.jpg)
Project Objective
• Develop a text chat application for message exchange among remote hosts:• One Server• Multiple (at most 4) Clients• Communication using TCP sockets
2
![Page 3: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/3.jpg)
Project Description
3
![Page 4: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/4.jpg)
Project Description: Clients
4
• When launched• Login to the server• Identify themselves to the server• Get list of other logged-in clients• Get buffered messages
• Clients send messages• Unicast• Broadcast
• Clients communicate with each other ONLYthrough the server
![Page 5: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/5.jpg)
Project Description: Server
5
• Facilitate exchange of messages between clients• Relays all messages• Maintains list of logged-in clients• Stores/Buffers messages for offline clients
![Page 6: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/6.jpg)
Commands / Events
6
• Assignment description lists the commands/eventsyou need to accept/handle
• Mandatory/Required output for eachcommand/event
• Follow command output syntax EXACTLY• Use the supplied format strings
• All printing using thecse4589_print_and_log(char* format, ...) function
• Extra output will make the automated grader fail test cases
![Page 7: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/7.jpg)
Dedicated CSE servers
7
• Ensure that your code compiles and operates correctly on the following 5 servers• stones.cse.buffalo.edu• highgate.cse.buffalo.edu• euston.cse.buffalo.edu• embankment.cse.buffalo.edu• undergound.cse.buffalo.edu
• For development and testing you should only use the directory we created for you on each of the 5 servers at /local/Fall_2019/<Your-UBIT-Name>/
• You should use these directories for development and testing (not your home directories)
![Page 8: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/8.jpg)
Project Requirements
8
• Make/Run on CSE Servers (stones, underground,
embankment, ….), make sure it compiles/runs on
these servers
• Only one program is running on each server, but
takes different arguments
• ./assignment1 s 4322
• ./assignment1 c 4322
• C or C++
• No external libraries for socket programming
• No external binaries/utilities (e.g., ifconfig, nslookup, etc.)
• Use the PA1 template (MANDATORY)
![Page 9: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/9.jpg)
How to run your program
• Server$ ./assignment1 s 4322
• Client$ ./assignment1 c 4322
• SHELL[PA1]$ IP…..[PA1]$ LOGIN 128.56.78.31 4322[PA1]$ …
9
![Page 10: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/10.jpg)
Commands• All commands should be in UPPER CASE• How to recognize the command input?
• Tokenize input
• Compare with command strings
10
![Page 11: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/11.jpg)
Commands
• [PA1]$ IP….IP:128.205.36.8….
• Display the external/public IP address
• 127.0.0.1 is NOT the correct address
• Create a UDP socket to any valid destination IP address
11
![Page 12: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/12.jpg)
Commands• [PA1]$ PORT….PORT:4322….
• Display the port number your host is listening on
12
![Page 13: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/13.jpg)
Commands
• [PA1]$ LOGIN 128.205.36.8 4322
• Clients login to the server• Identify themselves to the server• Get list of other logged-in clients• Get buffered messages
13
![Page 14: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/14.jpg)
Commands • List the currently logged-in clients• [PA1]$ LIST
14
1 stones.cse.buffalo.edu 128.205.36.32 4545
2 embankment.cse.buffalo.edu 128.205.36.35 5454
3 highgate.cse.buffalo.edu 128.205.36.33 5000
4 euston.cse.buffalo.edu 128.205.36.34 5100
![Page 15: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/15.jpg)
Commands • [PA1]$ SEND 128.45.12.1 Hello
• Send message to client with IP address: 128.45.12.1, through the server
• Max. length of message: 256 bytes
• Only valid ASCII characters
15
![Page 16: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/16.jpg)
Commands • [PA1]$ LOGOUT
• Logout from the server
• DO NOT terminate/exit the application
• Server should buffer messages for logged-out clients
16
![Page 17: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/17.jpg)
Commands
• [PA1]$ EXIT
• LOGOUT and exit the application with status code 0
• No buffering of messages for exited clients
17
![Page 18: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/18.jpg)
TCP Socket Flow
18
![Page 19: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/19.jpg)
Server Socket Setup
19
![Page 20: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/20.jpg)
Server Socket Setup
20
![Page 21: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/21.jpg)
Using connect()
21
![Page 22: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/22.jpg)
Select based I/O• select()
• For I/O MultiplexingCommand input on shell, TCP port listening, data incoming …
• File descriptorsSystem initialized OR User created/defines (e.g., files, socket())
22
Integer value Name0 Standard Input (stdin)1 Standard Output (stdout)2 Standard Error (stderr)
![Page 23: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/23.jpg)
Select based I/O• select() API function calls
• Add fd to the setFD_SET(int fd, fd_set *set);
• Remove fd from the setFD_CLR(int fd, fd_set *set);
• Return true if fd is in setFD_ISSET(int fd, fd_set *set);
• Clear all entries from the setFD_ZERO(fd_set *set);
23
![Page 24: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/24.jpg)
Select() Setup
24
![Page 25: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/25.jpg)
Select() Control flow
25
![Page 26: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/26.jpg)
Endianess• Different architectures use different byte
orderings internally for their multi-byte datatypes
• http://en.wikipedia.org/wiki/Endianness
26
![Page 27: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/27.jpg)
• Network byte-order is big-endian
• Need to convert all data to network byte-order before sending over a link
• htons(), htonl(), ntohs(), ntohl()• htons() host to network short• htonl() host to network long• ntohs() network to host short• ntohl() network to host long multi-byte integers
27
Endianess
![Page 28: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/28.jpg)
BONUS:P2P File Transfer
28
![Page 29: CSE 489/589 Programming Assignment 1lusu/cse4589/Fall2019/... · ProjectDescription:Clients 4 •Whenlaunched •Logintotheserver •Identify themselves to the server •Get list](https://reader033.fdocuments.in/reader033/viewer/2022042215/5ebd65bbca028e1af432a32e/html5/thumbnails/29.jpg)
• Additional functionality to transfer files between clients• Direct transfer between clients, NO server
involvement• Binary and text files• Open a TCP connection between the given two clients
• NO broadcast file transfers
29
P2P File Transfer