Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Microsoft 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,...

1 answer below »
Microsoft 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
een reported as stolen.
2. A server program that will repeatedly wait for
equests 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
ecvfrom() 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
ecvfrom() to get its reply.
Once this reply has a
ived, 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
equest.
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 wo
y 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
serve
Client
Single-
threaded
Serve
with
stolen cars
database
The messages being exchanged
"TNYMNI"
Client
Single-
threaded
Serve
with
stolen cars
database
In DB/Not in DB
The messages being exchanged
Client
Single-
threaded
serve
"killsvc"
Overview
 Will have to implement a very basic talk pai
 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 numbe
2. Create a socket
3. Prompt the user for a car license numbe
4. Send the number to the serve
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 numbe
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(…)
inds 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(…)
eceive a message and learn the address of its sende
(server side)
Summary
 Client side:
csd = socket(…)
sendto(csd, …)
ecvfrom(csd, …)
 Server side:
ssd = socket(…)
ind(…)
ecvfrom(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)
eturn(-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 numbe
ind address to an existing socket
if (bind(s, &sa, sizeof(struct sockaddr_in)) < 0) {
close(s);
eturn(-1);
}
if
Picking a port numbe
 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
uffer,
the message
strlen(buffer),
its length in bytes
0,
default flag values
(const struct sockaddr *)&server,
receive
length
length of struct sockadd
);
Some examples (IV)

receive a message, return number of bytes sent and
learn addresss of sende
n = recvfrom(
sd,
receiver’s socket
uffer,
the receiving buffe
BUFSIZE,
its length in bytes
0,
default flag values
(const struct sockaddr *)&from,
sende
&length
length of struct sockadd
);
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 serve
Each line will contain one license numbe
 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!
Answered 7 days After Mar 14, 2023

Solution

Mohith answered on Mar 22 2023
31 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here