-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudentClient.java
50 lines (41 loc) · 1.54 KB
/
StudentClient.java
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
// StudentClient.java
// gets input from user and sends to server
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class StudentClient {
// Host name or ip
final static String HOST = "localhost";
final static int PORT = 8000;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// input variables
String name = "";
String street = "";
String city = "";
String state = "";
String zip = "";
// get input
System.out.print("Please enter the student's name: ");
name = input.nextLine();
System.out.print("Please enter the student's street: ");
street = input.nextLine();
System.out.print("Please enter the student's city: ");
city = input.nextLine();
System.out.print("Please enter the student's state: ");
state = input.nextLine();
System.out.print("Please enter the student's zipcode: ");
zip = input.nextLine();
// connect to the server
try (Socket socket = new Socket(HOST, PORT);
ObjectOutputStream toServer =
new ObjectOutputStream(socket.getOutputStream());) {
// create a Student object and send to the server
StudentAddress s =
new StudentAddress(name, street, city, state, zip);
toServer.writeObject(s);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}