-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
70 lines (59 loc) · 1.76 KB
/
Client.java
File metadata and controls
70 lines (59 loc) · 1.76 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
import java.awt.*;
import java.io.*;
import java.net.*;
public class Client extends Thread
{
String ipf, pf;
Socket s;
boolean flag;
Client(String ip, String port) {
this.ipf = ip;
this.pf = port;
Interface.clientFlag = true;
}
public void closing() {
try {
s.close();
flag = false;
} catch (Exception e) {}
}
public void getMessage(String message) {
try {
if (!message.equals("//disable")) {
PrintWriter w = new PrintWriter(s.getOutputStream(), true);
w.println(message);
} else
{
PrintWriter w = new PrintWriter(s.getOutputStream(), true);
w.println(message);
closing();
}
} catch (Exception e) {}
}
public void run()
{
try
{
try {
Interface.ipLabel.setForeground(Color.gray);
Interface.ipLabel.setText("Trying to connect");
s = new Socket(ipf, Integer.parseInt(pf));
Interface.ipLabel.setForeground(Color.green);
Interface.ipLabel.setText("Connected");
System.out.println(s);
TextAction.online = true;
flag = true;
} catch (ConnectException e) {
DisconnectionAction.disconnection();
Interface.textArea.append("Unable to connect" + "\n");
Interface.status.setText("Unable to connect");
}
while (flag) {
sleep(100);
}
Interface.status.setText("Connect to somebody");
}
catch(Exception e)
{System.out.println("init error: " + e);}
}
}