Skip to content

Instantly share code, notes, and snippets.

@revox
Created January 18, 2015 09:41
Show Gist options
  • Select an option

  • Save revox/44d05cddf2bde0d9ffdd to your computer and use it in GitHub Desktop.

Select an option

Save revox/44d05cddf2bde0d9ffdd to your computer and use it in GitHub Desktop.
Multithreaded echo server
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