-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProfileClient.java
57 lines (45 loc) · 2.01 KB
/
ProfileClient.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
51
52
53
54
55
56
57
import javax.swing.*;
import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.util.ArrayList;
/**
* ProfileClient
*
* The .java file that the a user will run to connect to the server and access the social media functionality. It
* contains a main method that automatically connects the user to the server, and then runs the GUI to interact.
*
* N/A
*
* @author Team 60, Section 11
* @version 5/03/2021
*
*/
public class ProfileClient {
public static void main(String[] args) throws IOException, ClassNotFoundException {
try { //runs client side stuff
// getting localhost ip
InetAddress ip = InetAddress.getByName("localhost"); //"10.186.29.62"
// establish the connection with server port 1234
Socket s = new Socket(ip, 1234); //CHANGE FOR USE WITH UNITY TO 5555
// obtaining input and out streams
ObjectOutputStream dos = new ObjectOutputStream(s.getOutputStream());
ObjectInputStream dis = new ObjectInputStream(s.getInputStream());
//Confirm connection successful
JOptionPane.showMessageDialog(null, "Connection Established", "CampsGram",
JOptionPane.INFORMATION_MESSAGE);
//creates an IOMachine to easily access the server
IOMachine ioMachine = new IOMachine(dos, dis);
//Runs the Login GUI
LoginPageGUI Login = new LoginPageGUI(ioMachine);
Login.run();
} catch (IOException e) { //display error message is connection not established
JOptionPane.showMessageDialog(null, "Error: Connection Cannot be Established",
"Campsgram", JOptionPane.ERROR_MESSAGE);
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Error: There was an Error in the code " +
"somewhere", "Campsgram", JOptionPane.ERROR_MESSAGE);
}
}
}