Skip to content

Commit 80cd2de

Browse files
author
Sandy W
committed
client now sends command multiple times
1 parent 44c6e6b commit 80cd2de

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.class
2+
*~
3+
*.swp

client/Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ else while (menuSelection != 7) {
4444
for (int i = 0; i < 30; i++) {
4545
// make a new thread, tell it the hostname to connect to
4646
// and the command to run
47-
thrd = new Thread(new ClientThread(hostName, menuSelection));
47+
thrd = new Thread(new ClientThread(hostName, menuSelection, i));
4848
thrd.start(); // start the thread
4949
list.add(thrd); // add the thread to the end of the linked list
5050

client/ClientThread.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ public class ClientThread extends Thread {
1010
int menuSelection;
1111
String hostName;
1212
private static Socket socket = null;
13-
14-
ClientThread(String hostName, int menuSelection) {
13+
int threadNum;
14+
15+
ClientThread(String hostName, int menuSelection, int threadNum) {
1516
this.menuSelection = menuSelection;
1617
this.hostName = hostName;
18+
this.threadNum = threadNum;
1719
}
1820

1921
public void run() {
@@ -33,14 +35,15 @@ public void run() {
3335
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
3436
System.out.println("\nRequesting output for the '" + menuSelection + "' command from " + hostName);
3537
// send the command to the server
36-
out.println(Integer.toString(menuSelection));
37-
out.flush();
38+
for (int i = 0; i < 25; i++) {
39+
out.println(Integer.toString(menuSelection));
40+
out.flush();
41+
}
3842
System.out.println("Sent output");
3943
// read the command from the server
4044
String outputString = "hi";
4145
while (((outputString = in.readLine()) != null) && (!outputString.equals("END_MESSAGE"))) {
42-
System.out.println(outputString);
43-
System.out.println("Input read");
46+
System.out.println(threadNum + " " + outputString);
4447
}
4548
System.out.println("closing");
4649
try {

server/ServerThread.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public void run() {
2121
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
2222
System.out.print("Reader and writer created. ");
2323

24-
String inString = in.readLine();
24+
String inString;
25+
while ((inString = in.readLine()) == null);
2526
System.out.println("Read command " + inString);
2627

2728
String outString = CommandExecutor.run(inString);

0 commit comments

Comments
 (0)