Created
March 8, 2014 17:34
-
-
Save opiethehokie/9435533 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package test; | |
| import java.io.BufferedReader; | |
| import java.io.IOException; | |
| import java.io.InputStreamReader; | |
| import java.io.PrintWriter; | |
| import java.net.ServerSocket; | |
| import java.net.Socket; | |
| public class MultiThreadedSyncServer { | |
| public static void main(String[] args) throws IOException { | |
| final ServerSocket listener = new ServerSocket(8080); | |
| while (true) { | |
| new EchoThread(listener.accept()).start(); | |
| } | |
| } | |
| private static class EchoThread extends Thread { | |
| private Socket connection; | |
| public EchoThread(Socket socket) { | |
| this.connection = socket; | |
| } | |
| @Override | |
| public void run() { | |
| try (final BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); | |
| final PrintWriter out = new PrintWriter(connection.getOutputStream(), true)) { | |
| out.println(in.readLine()); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment