-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
43 lines (38 loc) · 895 Bytes
/
Server.java
File metadata and controls
43 lines (38 loc) · 895 Bytes
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
package DCCN;
import java.io.*;
import java.net.*;
public class Server {
private Socket socket = null;
private DataInputStream in = null;
private ServerSocket server = null;
public Server(int port)
{
try
{
server = new ServerSocket(port);
System.out.println("Server Started");
System.out.println("Waiting for a client...");
socket = server.accept();
System.out.println("Client accepted");
in = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
String line = "";
while(!line.equals("Over"))
{
try
{
line = in.readUTF();
System.out.println(line);
}
catch(Exception e) {};
}
System.out.println("Closing Connection");
in.close();
socket.close();
}
catch(Exception e) {};
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Server server = new Server(5000);
}
}