-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientHandler.java
More file actions
41 lines (33 loc) · 1.12 KB
/
ClientHandler.java
File metadata and controls
41 lines (33 loc) · 1.12 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
import java.net.*;
import java.io.*;
// Handles read write for client
public class ClientHandler implements Runnable{
private Socket clientSocket;
public ClientHandler(Socket clientSocket){
this.clientSocket = clientSocket;
}
public void run(){
String s;
BufferedReader in = null;
PrintWriter out = null;
try {
// Streams
out = new PrintWriter(clientSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
} catch (IOException e) {
//System.out.println("Exception caught when trying to listen on port " + portNum + " or listening for a connection");
System.out.println(e.getMessage());
}
// Read / Write
while(true)
{
try {
s = in.readLine();
out.println(s);
} catch (IOException e){
System.out.println("Read failed");
System.exit(-1);
}
}
}
}