Note : i\'m using Mac, and the program must work in eclipse Consider the figure
ID: 3790724 • Letter: N
Question
Note : i'm using Mac, and the program must work in eclipse
Consider the figure below for the following questions (v1 - 3). Each link has a full capacity of 45bags. Assume that Host A wants to transport a message of size 20^+ 10 bits to Host B. For all the questions below, you can region propagation, nodal processing and any questing delays. What if packet switching is used and the original message is broken down. into a total of 2000 products. You can neglect any packet headers, so that the assumption is that the pickets are composed of the data only. How long would it take for Host A to deliver the file to Host B? Now assume that message switching is used. In other words, the entire message is transmitted at once. hot we still implement since and forward at each node along the path. How long would n take for Host A to deliver the file to Host B?Explanation / Answer
public class VerySimpleChatServer { PrintWriter clientOutputStream; public class ClientHandler implements Runnable { BufferedReader reader; Socket sock; int noOfRequests; public ClientHandler(Socket clientSOcket) { try { sock = clientSOcket; InputStreamReader isReader = new InputStreamReader(sock.getInputStream()); reader = new BufferedReader(isReader); } catch (Exception ex) { ex.printStackTrace(); } } public void run() { String message; try { while ((message = reader.readLine()) != null) { System.out.println("read " + message); noOfRequests++; tellClient(message.toUpperCase()); if (noOfRequests == 10) { tellClient("You have asked for 10 messages already Closing connection"); clientOutputStream.close(); reader.close(); sock.close(); break; } } } catch (Exception ex) { ex.printStackTrace(); } } public void tellClient(String message) { try { clientOutputStream.println(message); clientOutputStream.flush(); } catch (Exception ex) { ex.printStackTrace(); } } } public static void main(String[] args) { new VerySimpleChatServer().go(); } public void go() { try { ServerSocket serverSock = new ServerSocket(5000); while(true) { Socket clientSocket = serverSock.accept(); clientOutputStream = new PrintWriter(clientSocket.getOutputStream()); Thread t = new Thread(new ClientHandler(clientSocket)); t.start(); System.out.println("got a connection"); } } catch (Exception ex) { ex.printStackTrace(); } } } ====== import java.io.*; import java.net.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class SimpleChatClient { JTextArea incoming; JTextField outgoing; BufferedReader reader; PrintWriter writer; Socket sock; public void go() { JFrame frame = new JFrame("Ludicrously Simple Chat Client"); JPanel mainPanel = new JPanel(); incoming = new JTextArea(15, 50); incoming.setLineWrap(true); incoming.setWrapStyleWord(true); incoming.setEditable(false); JScrollPane qScroller = new JScrollPane(incoming); qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); outgoing = new JTextField(20); JButton sendButton = new JButton("Send"); sendButton.addActionListener(new SendButtonListener()); mainPanel.add(qScroller); mainPanel.add(outgoing); mainPanel.add(sendButton); frame.getContentPane().add(BorderLayout.CENTER, mainPanel); setUpNetworking(); Thread readerThread = new Thread(new IncomingReader()); readerThread.start(); frame.setSize(650, 500); frame.setVisible(true); } private void setUpNetworking() { try { sock = new Socket("127.0.0.1", 5000); InputStreamReader streamReader = new InputStreamReader(sock.getInputStream()); reader = new BufferedReader(streamReader); writer = new PrintWriter(sock.getOutputStream()); System.out.println("networking established"); } catch(IOException ex) { ex.printStackTrace(); } } public class SendButtonListener implements ActionListener { public void actionPerformed(ActionEvent ev) { try { writer.println(outgoing.getText()); writer.flush(); } catch (Exception ex) { ex.printStackTrace(); } outgoing.setText(""); outgoing.requestFocus(); } } public static void main(String[] args) { new SimpleChatClient().go(); } class IncomingReader implements Runnable { public void run() { String message; try { while ((message = reader.readLine()) != null) { System.out.println("client read " + message); incoming.append(message + " "); } } catch (IOException ex) { ex.printStackTrace(); } } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.