-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
50 lines (45 loc) · 1.14 KB
/
Copy pathServer.java
File metadata and controls
50 lines (45 loc) · 1.14 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
package Assignment4;
import java.io.* ;
import java.net.*;
import java.util.*;
public class Server extends Thread
{
private static ArrayList<ServerHandle> connectedList = new ArrayList<>();
private int serverport;
private ServerSocket serverSocket;
public Server(int serverport) {
this.serverport = serverport;
}
public List<ServerHandle> get_connectedList()
{
return connectedList;
}
@SuppressWarnings("deprecation")
@Override
public void run() {
try {
// creating server socket
serverSocket = new ServerSocket(serverport);
while(true)
{
System.out.println("Waiting for connection....");
Socket clientsocket = serverSocket.accept();
System.out.println("Connected to: " + clientsocket);
ServerHandle handle = new ServerHandle(this,clientsocket);
connectedList.add(handle);
System.out.println(handle + "added to the list");
handle.start();
}
} catch (IOException e) {
e.printStackTrace();
}
finally {
try {
serverSocket.close();
Thread.currentThread().stop();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}