[mihi]
This commit is contained in:
mihi
2004-04-14 23:26:59 +00:00
committed by zzz
parent 7b03c95cfd
commit 24c69a26ea
3 changed files with 100 additions and 100 deletions

View File

@ -12,33 +12,33 @@ import java.net.*;
public class EchoServer extends Thread {
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(Integer.parseInt(args[0]));
while (true) {
Socket s = ss.accept();
new EchoServer(s);
}
ServerSocket ss = new ServerSocket(Integer.parseInt(args[0]));
while (true) {
Socket s = ss.accept();
new EchoServer(s);
}
}
private Socket s;
public EchoServer(Socket s) {
this.s=s;
start();
this.s=s;
start();
}
public void run() {
try {
InputStream in = s.getInputStream();
OutputStream out = s.getOutputStream();
byte[] b = new byte[4096];
int len;
while ((len = in.read(b)) != -1) {
out.write(b, 0, len);
}
} catch (SocketException ex) {
// nothing
} catch (IOException ex) {
ex.printStackTrace();
}
try {
InputStream in = s.getInputStream();
OutputStream out = s.getOutputStream();
byte[] b = new byte[4096];
int len;
while ((len = in.read(b)) != -1) {
out.write(b, 0, len);
}
} catch (SocketException ex) {
// nothing
} catch (IOException ex) {
ex.printStackTrace();
}
}
}