Mercurial > hg > Members > you > TreeVNC
view src/treeVnc/CreateThread.java @ 62:b2492abdae2a Version1.0 tip
Added tag TreeVNC_version1.0 for changeset 318ec7415073
author | Taninari YU <you@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 12 Aug 2012 22:13:39 +0900 (2012-08-12) |
parents | 32b266967c2c |
children |
line wrap: on
line source
package treeVnc; 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(int port,AcceptClient _acc) { acceptClient = _acc; this.port = port; } void newEchoClient(final BufferedReader is,final PrintStream os) { Runnable echoSender = new Runnable() { public void run() { // AcceptClient acceptClient = new AcceptClient(); // acceptClient new 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); } */ } } }