-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
54 lines (43 loc) · 1.02 KB
/
Server.java
File metadata and controls
54 lines (43 loc) · 1.02 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
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.ClassNotFoundException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
/**
* This class implements java Socket server
* @author pankaj
*
*/
public class Server extends Thread{
static Bus bus = new Bus();
static HashMap<Integer, Socket> h = new HashMap<Integer,Socket>();
static Socket socket = null ;
static ObjectInputStream ois = null;
static ObjectOutputStream oos = null;
public void run(){
System.out.println("Server start");
try {
ServerSocket server = new ServerSocket(4444);
while(true)
{
socket = server.accept();
ServerListenerThread l= new ServerListenerThread(socket, h);
l.start();
}
} catch (Exception e) {
System.out.println(e);
}
}
public static void exitServer() {
try {
ois.close();
oos.close();
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}