4. Servers are supposed to run for a long time without stopping—therefore, they
ID: 3603366 • Letter: 4
Question
4. Servers are supposed to run for a long time without stopping—therefore, they must be designed to provide good service no matter what their clients do. Examine the server TCPEchoServer.java and list 2 things you can think of that a client might do to cause the server to give poor service to other clients. Suggest improvements to fix the 2 problems that you find.
Based on your answers, or more specifically, your answers to "Examine the server TCPEchoServer.java and list anything you can think of that a client might do to cause it to give poor service to other clients," and revise TCPEchoClient.java to implement such a client, which I call a bad client. Your bad client should attempt to cause the server to provide poor services, in at least 2 different ways. (5 points, 2.5 for each bad behavior)
Then Based on your answers to "Suggest improvements to fix the problems that you find," revise TCPEchoServer.java to incorporate those improvements. You can call this improved server a bullet-proof server. (5 points, 2.5 for each improvement)
!!READ THIS!!: (To Chegg Answerer) I have asked this question 3 times already and gotten unrelated or insufficient/lousy answers, I understand how this code works and one way to make a bad client is by making it repeatedly write to the server thus blocking it from accepting messages from other clients, I fixed this by making the server able to accept multiple clients by creating multiple threads. I can't think of another way to make the client do something bad to the server so that is what I need help with. NOTE that it should be a change that can be implemented into the code of TCPEchoClient that makes it to something bad, NOT something bad about it already that can be improved. Then I need help with how to fix said change in TCPEchoServer. Thank you.
TCPEchoServer.java
import java.net.* I/ for Socket, ServerSocket, and InetAddress 5 import java.io.*; /7 for IOException and Input/OutputStrearm 6 7 public class TCPEchoServer 9 private static final int BUFSIZE= 32; // Size of receive buffer 10 11e public static void main(String[I args) throws IOException 12 13 14 15 16 17 18 19 20 21 if (args.length !-1) // Test for correct # of Aras throw new IllegaLArgumentExceptionC" Parameter(s): "); int se rvPort = Integer.parseInt(args[0]); // Create a server socket to accept client connection requests ServerSocket servSock - new ServerSocket(servPort); int recvMsgSize; // Size of received message byte receiveBuf = new byte [BUFSIZf]; // Receive buffer 23 24 25 26 27 28 29 30 31 32 while (true) I/ Run forever, accepting and servicing connections socket c1ntSock = servSock.accept(); // Get client connection SocketAddress clientAddressclntSock.getRemoteSocketAddressO; System.out.println( Handling client at " +clientAddress); InputStream in = clntSock.getInputStream(); OutputStream out = clntSock.getOutputStream(); // Receive until client closes connection, indicated by -1 return while ((recvMsgSize-in.read(receiveBuf)) !- -1) 34 35 36 37 38 39 40 41 out.write(receiveBuf, 0, recvMsgSize); clntSock.closeO; // Close the socket. We are done with this client! NOT REACHEDExplanation / Answer
//package org.pgs.seminar; 002 import javax.swing.*; 003 004 import java.awt.event.*; 005 import java.awt.*; 006 public class GuiDemo1 extends JFrame// implements ActionListener 007 { 008 public static void main(String [] args) 009 { 010 new GuiDemo1(); 011 } 012 JTextField name, amount, cash,change; 013 JRadioButton small, medium, large, thick, thin; 014 JCheckBox Beef, Mushroom, Ham,Onion,Pineapple; 015 JComboBox PizzaType, Order; 016 String type[]={"Select Pizza Type","Super Supreme","Meat Lover", 017 "Hawaiiwan Supreme","Bacon Supreme"}; 018 String orders[]={"Type of Order","DineIn","TakeOut"}; 019 public GuiDemo1 () 020 { 021 this.setTitle("PizzaHat"); 022 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 023 JPanel panel1 = new JPanel(); 024 panel1.setLayout(new GridBagLayout()); 025 addItem(panel1, new JLabel("Customer Name:"), 026 0, 0, 1, 1, GridBagConstraints.WEST); 027 addItem(panel1, new JLabel("AmountDue:"), 028 0, 7, 1, 1, GridBagConstraints.WEST); 029 addItem(panel1, new JLabel("Cash:"), 030 0, 8, 1, 1, GridBagConstraints.WEST); 031 addItem(panel1, new JLabel("Change:"), 032 0, 9, 1, 1, GridBagConstraints.WEST); 033 034 name = new JTextField(20); 035 amount = new JTextField("Php",10); 036 amount.setEditable(false); 037 cash = new JTextField(20); 038 change = new JTextField("Php",20); 039 change.setEditable(false); 040 addItem(panel1, name, 1, 0, 2, 1, 041 GridBagConstraints.WEST); 042 addItem(panel1, amount, 1, 7, 1, 1, 043 GridBagConstraints.WEST); 044 addItem(panel1, cash, 1, 8, 2, 1, 045 GridBagConstraints.WEST); 046 addItem(panel1, change, 1, 9, 1, 1, 047 GridBagConstraints.WEST); 048 addItem(panel1, new JComboBox(type), 049 0, 1, 1, 1, GridBagConstraints.EAST); 050 addItem(panel1, new JComboBox(orders), 051 0, 1, 2, 1, GridBagConstraints.EAST); 052 Box sizeBox = Box.createVerticalBox(); 053 small = new JRadioButton("Personal"); 054 medium = new JRadioButton("Regular"); 055 large = new JRadioButton("Family"); 056 ButtonGroup sizeGroup = new ButtonGroup(); 057 sizeGroup.add(small); 058 sizeGroup.add(medium); 059 sizeGroup.add(large); 060 sizeBox.add(small); 061 sizeBox.add(medium); 062 sizeBox.add(large); 063 sizeBox.setBorder( 064 BorderFactory.createTitledBorder("Size")); 065 addItem(panel1, sizeBox, 0, 2, 1, 1, 066 GridBagConstraints.NORTH); 067 068 Box topBox = Box.createVerticalBox(); 069 Beef = new JCheckBox("Beef"); 070 Ham = new JCheckBox("Ham"); 071 Onion = new JCheckBox("Onion"); 072 Pineapple = new JCheckBox("Pineapple"); 073 Mushroom = new JCheckBox("Mushroom"); 074 075 add(Beef); 076 add(Mushroom); 077 add(Ham); 078 add(Onion); 079 add(Pineapple); 080 topBox.add(Beef); 081 topBox.add(Mushroom); 082 topBox.add(Ham); 083 topBox.add(Onion); 084 topBox.add(Pineapple); 085 topBox.setBorder( 086 BorderFactory.createTitledBorder("Extra Toppings")); 087 addItem(panel1, topBox, 1, 2, 1, 1, 088 GridBagConstraints.NORTH); 089 090 this.add(panel1); 091 this.pack(); 092 this.setVisible(true); 093 } 094 private void addItem(JPanel p, JComponent c, 095 int x, int y, int width, int height, int align) 096 { 097 GridBagConstraints gc = new GridBagConstraints(); 098 gc.gridx = x; 099 gc.gridy = y; 100 gc.gridwidth = width; 101 gc.gridheight = height; 102 gc.weightx = 100.0; 103 gc.weighty = 100.0; 104 gc.insets = new Insets(5, 5, 5, 5); 105 gc.anchor = align; 106 gc.fill = GridBagConstraints.NONE; 107 p.add(c, gc); 108 109 } 110 }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.