-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentClient.java
More file actions
51 lines (41 loc) · 1.7 KB
/
StudentClient.java
File metadata and controls
51 lines (41 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
public class StudentClient
{
public static void main(String args[]) throws InterruptedException, IOException
{
StudentServer studentServer = new StudentServer();
Thread studentServerThread = new Thread(studentServer);
studentServerThread.start();
int port = 8898;
try (Socket socket = new Socket("localhost", port))
{
InputStream inputStream = socket.getInputStream();
OutputStream outputSteam = socket.getOutputStream();
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputSteam);
ProcessCommand(in, out, "averagegpa");
ProcessCommand(in, out, "averagegpa");
ProcessCommand(in, out, "student 3");
String id = ProcessCommand(in, out, "addstudent doogie howser\n3.9");
ProcessCommand(in, out, "student " + id);
id = ProcessCommand(in, out, "addstudent Batman\n3.1");
ProcessCommand(in, out, "student " + id);
ProcessCommand(in, out, "quit");
}
}
private static String ProcessCommand(Scanner in, PrintWriter out, String command)
{
command = command+"\n";
System.out.print("Sending:"+command);
out.println(command);
out.flush();
String response = in.nextLine();
System.out.println("Receiving:"+ response);
return response;
}
}