C programming: Fill Out the TODO'S IN THE PROGRAM : #include // EXIT_ codes #include // bool #include // printf, scanf #include // 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; }
C programming: Fill Out the TODO'S IN THE PROGRAM : #include // EXIT_ codes #include // bool #include // printf, scanf #include // 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; }
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
100%
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
#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;
}
// 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
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY