Question

In: Computer Science

Java or python. The clients need to be able to communicate with each other using the...

Java or python. The clients need to be able to communicate with each other using the command line. The "local chat" program should be implemented using a client/Server model based on UDP protocol.

Requirements:

1. The chat is performed between 2 clients and not the server.

2. The server will first start up and choose a port number. Then the server prints out its IP address and port number.

3. The client then will start up and create a socket based on the information provided by the server.

4. Now the client and the server can chat with each other by sending messages over the network.

5. The client/server MUST be able to communicate with each other in a continuous manner. (e.g. One side can send multiple messages without any replies from the other side)

6. There is no requirement on what language you use to implement this project, but your program should call upon the socket API for UDP to realize the functionality.

7. You should demonstrate your project using two machines (one for the client and one for the server. Pick your virtual machine as the client to communicate with your actual machine, which is server in our project).

8. You need to open at least 2 cmd window in your virtual machine to demonstrate multiple machine communicate with your server machine (actual machine)

Solutions

Expert Solution

// Client side implementation of UDP client-server model
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>

#define PORT   8080
#define MAXLINE 1024

// Driver code
int main() {
   int sockfd;
   char buffer[MAXLINE];
   char *hello = "Hello from client";
   struct sockaddr_in   servaddr;

   // Creating socket file descriptor
   if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) {
       perror("socket creation failed");
       exit(EXIT_FAILURE);
   }

   memset(&servaddr, 0, sizeof(servaddr));
  
   // Filling server information
   servaddr.sin_family = AF_INET;
   servaddr.sin_port = htons(PORT);
   servaddr.sin_addr.s_addr = INADDR_ANY;
  
   int n, len;
  
   sendto(sockfd, (const char *)hello, strlen(hello),
       MSG_CONFIRM, (const struct sockaddr *) &servaddr,
           sizeof(servaddr));
   printf("Hello message sent.\n");
      
   n = recvfrom(sockfd, (char *)buffer, MAXLINE,
               MSG_WAITALL, (struct sockaddr *) &servaddr,
               &len);
   buffer[n] = '\0';
   printf("Server : %s\n", buffer);

   close(sockfd);
   return 0;
}


Related Solutions

How do bacteria communicate with each other
How do bacteria communicate with each other
Need to able to solve this method WITHOUT using ANY java libraries. ------------------------------ import java.util.Scanner; public...
Need to able to solve this method WITHOUT using ANY java libraries. ------------------------------ import java.util.Scanner; public class nthroot { public static void main(String[] args) { Scanner sc = new Scanner(System.in);    // Read n (for taking the nth root) int num = Integer.parseInt(sc.nextLine());    // Read number to take the nth root of int number = Integer.parseInt(sc.nextLine());    // Read the desired precision int precision = Integer.parseInt(sc.nextLine());    // Print the answer System.out.println(findnthRoot(number, num, precision)); }    private static String...
Explain how the cells of the sponge communicate with each other. (Hint: Relate this to the...
Explain how the cells of the sponge communicate with each other. (Hint: Relate this to the makeup of the cell membrane.)
How is the dictyostelium discoideum communicate with each other and what is the motility and chemotaxis...
How is the dictyostelium discoideum communicate with each other and what is the motility and chemotaxis in dictyostelium discoideum please explain detailed
I only need to update this JAVA program to be able to : 1 ) Exit...
I only need to update this JAVA program to be able to : 1 ) Exit cleanly after creating the chart 2 ) change the pie chart to a perfect circle rather than an oval 3 ) provide a separate class driver import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.util.Scanner; import javax.swing.JComponent; import javax.swing.JFrame; // class to store the value and color mapping of the // pie segment(slices) class Segment { double value; Color color; // constructor public...
The average amount of time it takes for couples to further communicate with each other after...
The average amount of time it takes for couples to further communicate with each other after their first date has ended is 3.07 days. Is this average different for blind dates? A researcher interviewed 52 couples who had recently been on blind dates and found that they averaged 3.4 days to communicate with each other after the date was over. Their standard deviation was 0.837 days. What can be concluded at the the α = 0.10 level of significance? For...
The average amount of time it takes for couples to further communicate with each other after...
The average amount of time it takes for couples to further communicate with each other after their first date has ended is 2.01 days. Is this average different for blind dates? A researcher interviewed 68 couples who had recently been on blind dates and found that they averaged 2 days to communicate with each other after the date was over. Their standard deviation was 0.291 days. What can be concluded at the the αα = 0.10 level of significance? For...
The average amount of time it takes for couples to further communicate with each other after...
The average amount of time it takes for couples to further communicate with each other after their first date has ended is 3.91 days. Is this average different for blind dates? A researcher interviewed 47 couples who had recently been on blind dates and found that they averaged 3.3 days to communicate with each other after the date was over. Their standard deviation was 1.261 days. What can be concluded at the the α = 0.01 level of significance? For...
The average amount of time it takes for couples to further communicate with each other after...
The average amount of time it takes for couples to further communicate with each other after their first date has ended is 2.61 days. Is this average shorter for blind dates? A researcher interviewed 65 couples who had recently been on blind dates and found that they averaged 2.5 days to communicate with each other after the date was over. Their standard deviation was 0.661 days. What can be concluded at the the α = 0.01 level of significance? For...
The average amount of time it takes for couples to further communicate with each other after...
The average amount of time it takes for couples to further communicate with each other after their first date has ended is 3.19 days. Is this average shorter for blind dates? A researcher interviewed 58 couples who had recently been on blind dates and found that they averaged 3 days to communicate with each other after the date was over. Their standard deviation was 0.639 days. What can be concluded at the  αα = 0.01 level of significance? For this study,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT