Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

C programming: 

Fill Out the TODO'S IN THE PROGRAM :
 
#include <stdlib.h> // EXIT_ codes
#include <stdbool.h> // bool
#include <stdio.h> // printf, scanf
#include <string.h> // strlen, strcmp
#include "udp.h" // udp library
#define CLIENT_LISTENER_PORT 4097
#define SERVER_LISTENER_PORT 4098
#define MAX_CHARS_PER_MESSAGE 80
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
int main(int argc, char* argv[])
{
char *remoteIp;
char *mode;
int remotePort;
char str[MAX_CHARS_PER_MESSAGE+1];
bool quit = false;
bool sendMode;
// Verify arguments are good
bool goodArguments = (argc == 3);
if (goodArguments)
{
remoteIp = argv[1];
mode = argv[2];
goodArguments = (strcmp(mode, "server") == 0) || (strcmp(mode, "client") ==
0);
}
if (!goodArguments)
{
printf("usage: chat IPV4_ADDRESS MODE\n");
printf(" where:\n");
printf(" IPV4_ADDRESS is address of the remote machine\n");
printf(" MODE is either client or server\n");
exit(EXIT_FAILURE);
}
// Determine if client or server
 
 
 
 
 
 
 
bool client = strcmp(mode, "client") == 0;
// TODO: Open udp listener port number dependent on client/server role
// TODO: Determine remote port that you will send data to
// If you are server, send to client port, and vice versa
// TODO: Determine if it is your turn to send data or not,
// based on server or client mode
// sendMode = ...
// Display warning to not use spaces
printf("NOTE: When sending messages, DO NOT include spaces\n");
// Start chat loop, alternating between sending and receiving messages
while(!quit)
{
// send text
if (sendMode)
{
// TODO: Add code to get string from user and send
// TODO: Handle an error is sendUdpMessage returns false
// TODO: Leave while loop if QUIT was sent
}
// wait for text
else
{
// TODO: Add code to wait for a string from remote user
// TODO: Leave while loop if QUIT is received
}
// alternate between send and receive mode
sendMode = !sendMode;
}
// TODO: Close udp listener port

return EXIT_SUCCESS;
}
 
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY