1.A client program that will consult your server and
check if a given license plate is that of a car that has
been reported as stolen.
2.A server program that will
repeatedly
wait for
requests from its clients and reply whether a given
license plate is in its database of stolen carsMicrosoft Word - Assignment2.docx Updated last on Wednesday, March 01, 2023. COSC 3360/6310—FUNDAMENTALS OF OPERATING SYSTEMS Assignment #2: We have found your car! Due on Wednesday March 29, 2023 at 11:59:59 PM OBJECTIVE You will learn to use datagram sockets. OVERVIEW You are to write two programs: 1. A client program that will consult your server and check if a given license plate is that of a car that has been reported as stolen. 2. A server program that will repeatedly wait for requests from its clients and reply whether a given license plate is in its database of stolen cars. THE SERVER PROGRAM Your server will start by prompting the user to enter the name of a database of stolen cars as in: Enter today’s stolen car DB name: This file will contain one license plate per line with each license plate containing up to eight letters or digits as in: HIOFCR SHKSPR 2DIE4 BYOFCR TNYMNI 2FAST4U Note that spaces are expressly excluded. Your server should then prompt for a port number as in: Enter the server port number: 2468 It will then: 1. Create a datagram socket in the Internet domain, 2. Do a bind()to bind to the socket to the specified port number 3. Enter an infinite loop where it will repeatedly do a recvfrom() to receive license plate numbers from its clients then a sendto() to let each client know whether a given license plate number is, or is not in its database. All messages sent to the server will contain exactly one license plate number. For debugging and grading purposes, your server should print out every license plate it receives and its status as in: 2DIE4: Reported as stolen STOL3N: Not in the database Your server will keep accepting client requests until it receives a “killsvc” message from one of its clients. THE CLIENT PROGRAM Your client should start by prompting the user for a server host name and a server port number as in: Enter the server host name: localhost Enter the server port number: 2468 It should then create a datagram socket, and prompt the user for a car license plate as in: Enter a license plate number: BYOFCR It should then create a datagram socket, do a sendto() to send that number to the server then a recvfrom() to get its reply. Once this reply has arrived, the client should display the outcome of the query as in: 2DIE4: Reported as stolen STOL3N: Not in the database Unlike the server, each client will only handle a single request. HINTS 1. Please refer one of these three online socket tutorials: https://www.geeksforgeeks.org/udp-server-client- implementation-c/ https://www.programminglogic.com/sockets- programming-in-c-using-udp-datagrams/ https://www.softprayog.in/programming/network- socket-programming-using-udp-in-c You can also find these links in our course Teams pages. You can include any code from these documents in your submissions. 2. Use a single-threaded server to keep things simple. You will not have to not worry about zombies and can safely ignore all suggestions to use fireman() function. 3. Unlike the server, each client will only handle a single request. 4. More tutorial links will be posted on Teams when found. Microsoft PowerPoint - Explanations2.pptx THE SECOND SPRING 2023 COSC 3360/6310 ASSIGNMENT THE PROBLEM Build a client server pair that tells police officers whether a given car has been reported as stolen. To get credit, your two programs must Be written in C or C++ Use datagram sockets in the internet domain YOUR PROGRAMS Client IPC Single- threaded server Client Single- threaded Server with stolen cars database The messages being exchanged "TNYMNI" Client Single- threaded Server with stolen cars database In DB/Not in DB The messages being exchanged Client Single- threaded server "killsvc" Overview Will have to implement a very basic talk pair Will have to write A client that will send one request, wait for one reply then terminate. A single-threaded server that will wait for requests from multiple clients Client side Client will 1. Prompt the user for server host name and port number 2. Create a socket 3. Prompt the user for a car license number 4. Send the number to the server 5. Receive the server’s reply and print it out 6. Terminate Server side Server will 1. Read in the day's stolen car database 2. Create a socket 3. Bind an address to that socket 4. Wait for incoming messages 7. Receive and print out a message from client 8. Consult its DB and send a Yes/No reply to the client 9. Wait for next client message request Server side Server will 1. Read in the day's stolen car database 2. Read in a port number 3. Create a socket 4. Bind an address to that socket 5. Wait for incoming messages 7. Receive and print out a message from client 8. Consult its DB and send a Yes/No reply to the client 9. Wait for next client message request Loop will end when the server receives a killsvc message Communicating through sockets UDP socket calls (I) socket(…) creates a new socket of a given socket type (both client and server sides) bind(…) binds a socket to a socket address structure (server side) close(…) close socket(server side) UDP socket calls (II) sendto(…) sends a message (both sides) recvfrom(…) receive a message and learn the address of its sender (server side) Summary Client side: csd = socket(…) sendto(csd, …) recvfrom(csd, …) Server side: ssd = socket(…) bind(…) recvfrom(ssd, …) sendto(ssd, …) Bad news and good news The bad news is that socket calls are somewhat esoteric Might feel you are not fully understanding what you are writing The good news is most of these mysterious options are fairly standard Some examples (I) // create socket if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)="" return(-1);="" so="" far="" so="" good="" some="" examples="" (ii)="" ="" gethostname(myname,="" maxhostname);="" skip="" for="" wsl!="" get="" host="" address="" structure="" hp="gethostbyname(myname);" sa.sin_family="hp-">h_addrtype; // host address sa.sin_port = htons(portnum); // set port number //bind address to an existing socket if (bind(s, &sa, sizeof(struct sockaddr_in)) < 0) { close(s); return(-1); } // if picking a port number your port number should be unique should not interfere with other students' programs greater than or equal to 1024 lower numbers are reserved for privileged applications some examples (iii) // send a message and return number of bytes sent n = sendto( sd, // sender’s socket buffer, // the message strlen(buffer), // its length in bytes 0, // default flag values (const struct sockaddr *)&server, // receiver length // length of struct sockaddr ); some examples (iv) // receive a message, return number of bytes sent and learn addresss of sender n = recvfrom( sd, // receiver’s socket buffer, // the receiving buffer bufsize, // its length in bytes 0, // default flag values (const struct sockaddr *)&from, // sender &length //length of struct sockaddr ); implementation details doing networking assignments on your pc the host name of a windows pc does not include its domain jfparis@odeon:~$ hostname odeon hp = gethostbyname("odeon"); does not always work use instead localhost hp = gethostbyname(localhost); the stolen car database very short file read in by the server each line will contain one license number hiofcr shkspr 2die4 … no spaces and no more than 8 characters some good tutorials https://www.geeksforgeeks.org/udp-server-client-implementation-c/ https://www.programminglogic.com/sockets-programming-in-c-using- udp-datagrams/ https://www.softprayog.in/programming/network-socket-programming- using-udp-in-c can lift from them all the code you need. jfparis@odeon:~/spring23$ ./client2 enter the server host name: localhost enter the server port number: 3456 enter a car license plate number: stol3n stol3n: not in the database. jfparis@odeon:~/spring23$ ./client2 enter the server host name: localhost enter the server port number: 3456 enter a car license plate number: tnymni tnymni: reported as stolen. jfparis@odeon:~/spring23$ ./client2 enter the server host name: localhost enter the server port number: 3456 enter a car license plate number: killsvc client terminates. bye! 0)="" {="" close(s);="" return(-1);="" }="" if="" picking="" a="" port="" number="" ="" your="" port="" number="" should="" be="" unique="" ="" should="" not="" interfere="" with="" other="" students'="" programs="" greater="" than="" or="" equal="" to="" 1024="" ="" lower="" numbers="" are="" reserved="" for="" privileged="" applications="" some="" examples="" (iii)="" ="" send="" a="" message="" and="" return="" number="" of="" bytes="" sent="" n="sendto(" sd,="" sender’s="" socket="" buffer,="" the="" message="" strlen(buffer),="" its="" length="" in="" bytes="" 0,="" default="" flag="" values="" (const="" struct="" sockaddr="" *)&server,="" receiver="" length="" length="" of="" struct="" sockaddr="" );="" some="" examples="" (iv)="" ="" receive="" a="" message,="" return="" number="" of="" bytes="" sent="" and="" learn="" addresss="" of="" sender="" n="recvfrom(" sd,="" receiver’s="" socket="" buffer,="" the="" receiving="" buffer="" bufsize,="" its="" length="" in="" bytes="" 0,="" default="" flag="" values="" (const="" struct="" sockaddr="" *)&from,="" sender="" &length="" length="" of="" struct="" sockaddr="" );="" implementation="" details="" doing="" networking="" assignments="" on="" your="" pc="" ="" the="" host="" name="" of="" a="" windows="" pc="" does="" not="" include="" its="" domain="" jfparis@odeon:~$="" hostname="" odeon="" ="" hp="gethostbyname("Odeon");" does="" not="" always="" work="" ="" use="" instead="" localhost="" hp="gethostbyname(localhost);" the="" stolen="" car="" database="" ="" very="" short="" file="" ="" read="" in="" by="" the="" server="" each="" line="" will="" contain="" one="" license="" number="" ="" hiofcr="" shkspr="" 2die4="" …="" no="" spaces="" and="" no="" more="" than="" 8="" characters="" some="" good="" tutorials="" ="" https://www.geeksforgeeks.org/udp-server-client-implementation-c/="" ="" https://www.programminglogic.com/sockets-programming-in-c-using-="" udp-datagrams/="" ="" https://www.softprayog.in/programming/network-socket-programming-="" using-udp-in-c="" ="" can="" lift="" from="" them="" all="" the="" code="" you="" need.="" jfparis@odeon:~/spring23$="" ./client2="" enter="" the="" server="" host="" name:="" localhost="" enter="" the="" server="" port="" number:="" 3456="" enter="" a="" car="" license="" plate="" number:="" stol3n="" stol3n:="" not="" in="" the="" database.="" jfparis@odeon:~/spring23$="" ./client2="" enter="" the="" server="" host="" name:="" localhost="" enter="" the="" server="" port="" number:="" 3456="" enter="" a="" car="" license="" plate="" number:="" tnymni="" tnymni:="" reported="" as="" stolen.="" jfparis@odeon:~/spring23$="" ./client2="" enter="" the="" server="" host="" name:="" localhost="" enter="" the="" server="" port="" number:="" 3456="" enter="" a="" car="" license="" plate="" number:="" killsvc="" client="" terminates.=""> 0) { close(s); return(-1); } // if picking a port number your port number should be unique should not interfere with other students' programs greater than or equal to 1024 lower numbers are reserved for privileged applications some examples (iii) // send a message and return number of bytes sent n = sendto( sd, // sender’s socket buffer, // the message strlen(buffer), // its length in bytes 0, // default flag values (const struct sockaddr *)&server, // receiver length // length of struct sockaddr ); some examples (iv) // receive a message, return number of bytes sent and learn addresss of sender n = recvfrom( sd, // receiver’s socket buffer, // the receiving buffer bufsize, // its length in bytes 0, // default flag values (const struct sockaddr *)&from, // sender &length //length of struct sockaddr ); implementation details doing networking assignments on your pc the host name of a windows pc does not include its domain jfparis@odeon:~$ hostname odeon hp = gethostbyname("odeon"); does not always work use instead localhost hp = gethostbyname(localhost); the stolen car database very short file read in by the server each line will contain one license number hiofcr shkspr 2die4 … no spaces and no more than 8 characters some good tutorials https://www.geeksforgeeks.org/udp-server-client-implementation-c/ https://www.programminglogic.com/sockets-programming-in-c-using- udp-datagrams/ https://www.softprayog.in/programming/network-socket-programming- using-udp-in-c can lift from them all the code you need. jfparis@odeon:~/spring23$ ./client2 enter the server host name: localhost enter the server port number: 3456 enter a car license plate number: stol3n stol3n: not in the database. jfparis@odeon:~/spring23$ ./client2 enter the server host name: localhost enter the server port number: 3456 enter a car license plate number: tnymni tnymni: reported as stolen. jfparis@odeon:~/spring23$ ./client2 enter the server host name: localhost enter the server port number: 3456 enter a car license plate number: killsvc client terminates. bye!>