Created
March 18, 2018 09:38
-
-
Save mbakhoff/83332fdf52961a0148cb9eefbf35fe75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.DataInputStream; | |
import java.io.DataOutputStream; | |
import java.io.IOException; | |
import java.net.Socket; | |
class ClientHandler implements Runnable { | |
private final Socket s; | |
public ClientHandler(Socket s) { | |
this.s = s; | |
} | |
@Override | |
public void run() { | |
try { | |
try (DataInputStream in = new DataInputStream(s.getInputStream()); | |
DataOutputStream out = new DataOutputStream(s.getOutputStream())) { | |
int stringCount = in.readInt(); | |
for (int i = 0; i < stringCount; i++) { | |
out.writeUTF(in.readUTF()); | |
} | |
} | |
} finally { | |
try { | |
s.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment