echoserverThreaded.java
Submitted by rac on 15 January, 2008 - 09:40.
-
package hsz.ITDP.rac.uebungen.echoClientSrv;
-
import java.io.BufferedReader;
-
import java.io.IOException;
-
import java.io.InputStreamReader;
-
import java.io.PrintWriter;
-
import java.net.ServerSocket;
-
import java.net.Socket;
-
-
-
this.sock = sockin;
-
}
-
public void run() {
-
BufferedReader in = null;
-
PrintWriter out = null;
-
while ( true ) {
-
-
try {
-
boolean exit = false;
-
while(!exit || in != null) {
-
if(userwrote.equals("exit")) {
-
exit = true;
-
} else {
-
System.out.println("User "+ sock.getInetAddress() +" on socket "+sock.getLocalSocketAddress()+"wrote: "+userwrote);
-
out.println(userwrote);
-
}
-
}
-
// TODO: handle exception
-
} finally {
-
if (in != null)
-
try {
-
in.close();
-
// TODO: handle exception
-
}
-
if (out != null)
-
try {
-
out.close();
-
// TODO: handle exception
-
}
-
-
if (sock != null)
-
try {
-
sock.close();
-
// TODO: handle exception
-
}
-
-
}
-
}
-
}
-
-
try {
-
ServerSocket srvsock = null;
-
int srvPort = 9998; // Integer.parseInt(args[0]);
-
while(true) {
-
newThread.start();
-
}
-
-
-
// TODO: handle exception
-
}
-
}
-
-
-
}
»
- Printer-friendly version
- Download PDF
- 2809 reads

Post new comment