Created
January 18, 2015 09:41
-
-
Save revox/44d05cddf2bde0d9ffdd to your computer and use it in GitHub Desktop.
Multithreaded echo server
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
| import java.io.*; | |
| import java.net.*; | |
| class simpleMultiThreadedEchoServer | |
| { | |
| public static void main(String[] argv) throws Exception | |
| { | |
| ServerSocket s = new ServerSocket(5000); | |
| Transaction k; | |
| while (true) | |
| { | |
| k = new Transaction(s.accept()); | |
| k.start(); | |
| } | |
| } | |
| } | |
| class Transaction extends Thread | |
| { | |
| InputStream b; | |
| OutputStream p; | |
| public Transaction(Socket s) throws Exception | |
| { | |
| b=s.getInputStream(); | |
| p =s.getOutputStream(); | |
| } | |
| public void run() | |
| { | |
| int c; | |
| try | |
| { | |
| while((c=b.read())!=-1) | |
| { | |
| p.write((char)c); | |
| p.flush(); | |
| System.out.print((char)c); | |
| } | |
| } | |
| catch (Exception e) | |
| { | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment