Ad code to the class myclient of lecture 1 to impose a


Question 1: Add code to the class: MyClient in example 3 of lecture 1 to impose a timeout of 5 seconds. If a timeout does occur, a message "timed out on receiver" should be displayed and the client should be terminated.

Hints:

1. You need to call the java method: setSoTimeout(5000) of class: DatagramSocket.

2. You need an extra catch-block with the exception class: SocketTimeoutException.

Question 2: In a client-serve program we normally run the server first and then the client. If we run the client first we get error message. We like to run the client first and then the server. Change the class: MyClient in example 1 of lecture 2 (which is on sockets) to avoid any exception error. In other words as long as the server is not connected the client stays on with no error.

Note: Only copy/paste the class: MyClient under the word: Answer.

Hints: The client has to loop around until the server gets connect. You may need to include more try-catch block(s) or/and more specific exception class(s). Run the client many times to make sure you do not get any type of exception errors.

Question 3 Using RMI, write an application for a prototype opinion poll system. Assume that only one issue is being polled. Respondents may choose yes, or no. Write a client-server application to accept the votes, keep the tally (in memory), and provide the current counts to those who are interested.

Note: Fill the following classes. Do not change the name of the classes and the interface. Copy/paste your answer under the word: Answer.

Note: This question is a shorten version of exercise: 9 on page 230 of your book.

Note: You do not need to make a number of client programs. Make one server and one client programs. Keep the server running and run the client several times. For example I run the client three times as follows. Note that this is just a sample example. Your answer must work for any number of clients:

Enter port: What is your vote?[yes|no] : yes

Yes = 1; No = 0

Enter port: What is your vote?[yes|no] : no

Yes = 1; No = 1

Enter port: What is your vote?[yes|no] : no

Yes = 1; No = 2

Server Side:

import java.rmi.*;

import java.rmi.server.*;

import java.rmi.registry.Registry;

import java.rmi.registry.LocateRegistry;

import java.net.*;

public class Chapter7Problem9Server{

public static void main(String args[]){

}

}

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

import java.rmi.*;

import java.rmi.server.*;

public class VoteServerImpl extends UnicastRemoteObject implements VoteServerInterface {

}

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

import java.rmi.Remote;

public interface VoteServerInterface extends Remote {

public String castVote(char vote )throws java.rmi.RemoteException;

}

Client Side:

import java.rmi.*;

import java.util.*;

public class Chapter7Problem9Client{

public static void main(String args[]){

}
}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

import java.rmi.Remote;

public interface VoteServerInterface extends Remote {

public String castVote(char vote )throws java.rmi.RemoteException;
}

Request for Solution File

Ask an Expert for Answer!!
Computer Networking: Ad code to the class myclient of lecture 1 to impose a
Reference No:- TGS01035821

Expected delivery within 24 Hours