-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTGServerThread.java
More file actions
66 lines (54 loc) · 1.62 KB
/
TGServerThread.java
File metadata and controls
66 lines (54 loc) · 1.62 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
//
// TGServerThread.java
//
// Written by : Priyank Patel <pkpatel@cs.stanford.edu>
//
// Accepts connection requests and processes them
// socket
import java.net.*;
import java.io.*;
// Swing
import javax.swing.JTextArea;
// Crypto
import java.security.*;
import java.security.spec.*;
import java.security.interfaces.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.crypto.interfaces.*;
public class TGServerThread extends Thread {
private TGServer _tgs;
private ServerSocket _serverSocket = null;
private int _portNum;
private String _hostName;
private JTextArea _outputArea;
public TGServerThread(TGServer tgs) {
super("AuthServerThread");
_tgs = tgs;
_portNum = tgs.getPortNumber();
_outputArea = tgs.getOutputArea();
_serverSocket = null;
try {
InetAddress serverAddr = InetAddress.getByName(null);
_hostName = serverAddr.getHostName();
} catch (UnknownHostException e) {
_hostName = "0.0.0.0";
}
}
// Accept connections and service them one at a time
public void run() {
try {
_serverSocket = new ServerSocket(_portNum);
_outputArea.append("AS waiting on " + _hostName + " port " + _portNum);
while (true) {
Socket socket = _serverSocket.accept();
//
// Got the connection, now do what is required
//
}
} catch (Exception e) {
System.out.println("AS thread error: " + e.getMessage());
e.printStackTrace();
}
}
}