-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
76 lines (65 loc) · 1.68 KB
/
Client.java
File metadata and controls
76 lines (65 loc) · 1.68 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
class Client extends Thread {
InetAddress host = null;
Socket socket = null;
ObjectOutputStream oos = null;
ObjectInputStream ois = null;
private String str;
static int index = 1;
ClientWindow cw;
//ClientData data = new ClientData(2);
public void run() {
try {
host = InetAddress.getLocalHost();
socket = new Socket(host.getHostName(), 4444);
// oos = new ObjectOutputStream(socket.getOutputStream());
// oos.writeObject(data);
ois = new ObjectInputStream(socket.getInputStream());
String message = (String) ois.readObject();
System.out.println("Client Received: " + message);
if(message.equals("Ok"));
//ClientWindow.end(str);
} catch (Exception e) {
}
}
public void SendStopInStationToServer(String s)
{
try {
str=s;
oos = new ObjectOutputStream(socket.getOutputStream());
ClientData cd = new ClientData(index++, s);
oos.writeObject(cd);
} catch (IOException e) {
e.printStackTrace();
}
}
public void connectToServer()
{
try {
host = InetAddress.getLocalHost();
socket = new Socket(host.getHostName(), 4444);
oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject(index++);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void closeClient() {
try {
ois.close();
oos.close();
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}