Client-Server

  1. Sockets , Client - Server 1 : How can I create an application that can talk with other copies of the same application, or different applications, on the network?
  2. Sockets , Client - Server 2 : How do I create client/server architectures? What code and techniques are necessary to create the server and the client?
  3. Sockets , Client - Server 3 : How do I communicate with UNIX and other machines using connection-based (e.g. TCP) or connection-less (e.g. UDP) packets?
  4. Sockets , Client - Server 4 : How do I use Remote procedure Calls? What is a Remote procedure Call?
  5. Sockets , Client - Server 5 : How do I appropriately design a program so that it effectively uses Remote Procedure Calls? How do I know when and when not to use RPCs?
  6. Sockets , Client - Server 6 : Indicate the trueness of the following statements by marking them "True" or "False". Briefly justify your answers.
    1. UICI uses private channels to communicate to different clients, i.e. server create distinct ports for each client.
    2. Sockets can not be used to communicate between processes on the same machine.
  7. Sockets , Client - Server 7 : List two client-server communication features supported by sockets but not by UICI.
  8. Sockets , Client - Server 8 : Consider the server program given below:
    /* assume include files:   
    
          */
    
    void * handle_request (void * a)
    { int connection; 
      time_t nticks; 
      char buf [512];
      nticks = time (NULL); 
      connection = *(int *)a;
      sprintf (buf, "%.24s", ctime (&nticks));
      write (connection, buf, strlen (buf) + 1);
      close (connection); 
      pthread_exit (NULL);
    }
    
    int main (int argc, char * argv [])
    { int sockfd, newsockfd, clilen, childpid, STCP_PORT, threaded = 0;
      time_t ticks; char cmd [255], buf [512];
      struct sockaddr_in server1, client1;
      if (argc != 2) exit (1);
      threaded = atoi (argv [1]);
      STCP_PORT = 6300;    /* port servers listens to */
      bzero ((char *)&server1, sizeof (server1));
      if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) < 0) 
    	perror ("Socket fails");
      server1.sin_family = AF_INET;
      server1.sin_addr.s_addr = htonl (INADDR_ANY);
      server1.sin_port = htons (STCP_PORT);
      if (bind (sockfd, (struct sockaddr *)& server1,  sizeof (server1)) < 0) 
    	{ perror("Server socket bind failed"); exit (1); }
      listen (sockfd, 1);
      for (;;)
      { int i, fd, len; time_t nticks; pthread_t servt;
        nticks = time (NULL); clilen = sizeof (client1); strcpy (cmd, "");
        newsockfd = accept (sockfd, (struct sockaddr *) & client1, &clilen);
        if (newsockfd < 0) { 
    	close (sockfd); 
    	fprintf (stderr, "%s\n", "Server accept failed");
    	 exit (1);
         }
        if (threaded == 0) {
            sprintf (buf, "%.24s", ctime (&nticks));
            write (newsockfd, buf, strlen (buf) + 1); close (newsockfd);
        } else {
            pthread_create (&servt, NULL, handle_request, (void *)&newsockfd);
        }
      } 
    }
    

    A. Draw two client-server architecture diagrams for the communication channels used by this server assuming there are two clients and command line argument was 0. Clearly indicate ports common across two diagrams. Consider Fig. 12.2 and Fig. 12.3 (pp. 434) from the Textbook for notation.
    B. Draw a client-server diagram assume that the command line argument is 1.
    C. Discuss the pros and cons of threaded implementation of this "time" server.
  9. Client - Server + Threads 1 : How will one decide if a server should be serial or multi-threaded? Provide examples of applications which will benfit from multi-threaded servers.
  10. Client - Server + Files 1 : Consider extending the notion of "symbolic links" across internet. What are naming mechanism to uniquely identify files/resource on the internet? What would be the content of the "internet symbolic link" file to point to a file on internet?
  11. Client - Server + Files 2 : Recall that "sockets" can be considered as a generalization of "pipes" for internet. Consider extending the notion of "filters" and "|" in unix commands for internet. An possible application is to compose the programs available at different web-sites for new applications. Define a common input/output interface for internet-filter-programs. Describe how "sockets" can be used to implement internet-based "|".