Mercurial > hg > Members > nobuyasu > tightVNCProxy
view src/myVncProxy/CreateThread.java @ 168:f7f4c3fdbbea
update
author | one |
---|---|
date | Sat, 10 Sep 2011 04:11:30 +0900 |
parents | 4297c2011b71 |
children |
line wrap: on
line source
package myVncProxy; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; import java.net.BindException; import java.net.ServerSocket; import java.net.Socket; public class CreateThread implements Runnable { ServerSocket echoServer; AcceptClient acceptClient; int port; public CreateThread(AcceptClient _acc) { acceptClient = _acc; port = 9999; } public CreateThread(AcceptClient _acc , int port) { acceptClient = _acc; this.port = port; } void newEchoClient(final BufferedReader is,final PrintStream os) { Runnable echoSender = new Runnable() { public void run() { acceptClient.transferParentAddrerss(is,os); } }; new Thread(echoSender).start(); } void selectPort(int p) { int port = p; while (true) { try { initServSock(port); break; } catch (BindException e) { port++; continue; } catch (IOException e) { } } System.out.println("accept Echo port = " + port); } void initServSock(int port) throws IOException { echoServer = new ServerSocket(port); this.port = port; } public void run() { selectPort(port); while (true) { try { // echoServer = new ServerSocket(9999); Socket clientSocket = echoServer.accept(); BufferedReader is = new BufferedReader(new InputStreamReader( clientSocket.getInputStream())); PrintStream os = new PrintStream(clientSocket.getOutputStream()); newEchoClient(is,os); // acceptClient.transferParentAddrerss(is, os); } catch (IOException e) { System.out.println(e); } /* try { echoServer.close(); } catch (IOException e) { System.out.println(e); } */ } } }