Skip to content

Instantly share code, notes, and snippets.

@mbakhoff
Created March 18, 2018 09:38
Show Gist options
  • Save mbakhoff/83332fdf52961a0148cb9eefbf35fe75 to your computer and use it in GitHub Desktop.
Save mbakhoff/83332fdf52961a0148cb9eefbf35fe75 to your computer and use it in GitHub Desktop.
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