Question: having trouble with a UDP c program where I need to make a knock knock joke where the client initiates the conversation with the conversation
having trouble with a UDP c program where I need to make a knock knock joke where the client initiates the conversation with the conversation being:
Client Server: Knock! Knock!
Server Client: Who is there?
Client Server: Robin.
Server Client: Robin who?
Client Server: Robin you! Hand over your cash!
the files i need to complete are udpknockknockjokeclient.c and udpknockknockjokeserver.c I should also note that the program needs to be manually terminated and not automatically after program is completed.
they need to be utilized with the files:
AddressUtility.c
#include
#include
#include
#include
void PrintSocketAddressconst struct sockaddr address FILE stream
Test for address and stream
if address NULL stream NULL
return;
void numericAddress; Pointer to binary address
Buffer to contain result IPv sufficient to hold IPv
char addrBufferINETADDRSTRLEN;
inportt port; Port to print
Set pointer to address based on address family
switch addresssafamily
case AFINET:
numericAddress &struct sockaddrin addresssinaddr;
port ntohsstruct sockaddrin addresssinport;
break;
case AFINET:
numericAddress &struct sockaddrin addresssinaddr;
port ntohsstruct sockaddrin addresssinport;
break;
default:
fputsunknown type stream; Unhandled type
return;
Convert binary to printable address
if inetntopaddresssafamily, numericAddress, addrBuffer,
sizeofaddrBuffer NULL
fputsinvalid address stream; Unable to convert
else
fprintfstreams addrBuffer;
if port Zero not valid in any socket addr
fprintfstreamu port;
bool SockAddrsEqualconst struct sockaddr addr const struct sockaddr addr
if addr NULL addr NULL
return addr addr;
else if addrsafamily addrsafamily
return false;
else if addrsafamily AFINET
struct sockaddrin ipvAddrstruct sockaddrin addr;
struct sockaddrin ipvAddrstruct sockaddrin addr;
return ipvAddrsinaddr.saddr ipvAddrsinaddr.saddr
&& ipvAddrsinport ipvAddrsinport;
else if addrsafamily AFINET
struct sockaddrinipvAddrstruct sockaddrin addr;
struct sockaddrinipvAddrstruct sockaddrin addr;
return memcmp&ipvAddrsinaddr, &ipvAddrsinaddr,
sizeofstruct inaddr && ipvAddrsinport
ipvAddrsinport;
else
return false;
DieWithMessage.c
#include
#include
void DieWithUserMessageconst char msg const char detail
fputsmsg stderr;
fputs: stderr;
fputsdetail stderr;
fputc
stderr;
exit;
void DieWithSystemMessageconst char msg
perrormsg;
exit;
Practical.h
#ifndef PRACTICALH
#define PRACTICALH
#include
#include
#include
Handle error with user msg
void DieWithUserMessageconst char msg const char detail;
Handle error with sys msg
void DieWithSystemMessageconst char msg;
Print socket address
void PrintSocketAddressconst struct sockaddr address FILE stream;
Test socket address equality
bool SockAddrsEqualconst struct sockaddr addr const struct sockaddr addr;
Create, bind, and listen a new TCP server socket
int SetupTCPServerSocketconst char service;
Accept a new TCP connection on a server socket
int AcceptTCPConnectionint servSock;
Handle new TCP client
void HandleTCPClientint clntSocket;
Create and connect a new TCP client socket
int SetupTCPClientSocketconst char server const char service;
enum sizeConstants
MAXSTRINGLENGTH
BUFSIZE
;
#endif PRACTICALH
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
