Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!news2.arglkargh.de!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: Michal Kleczek Newsgroups: comp.lang.java.programmer Subject: Re: java proxy server problem Date: Mon, 27 May 2013 11:28:41 +0200 Organization: Aioe.org NNTP Server Lines: 37 Message-ID: References: NNTP-Posting-Host: ZzNcjiVEyHSgCAKxRrAf8w.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120824 Thunderbird/15.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:24185 On 2013-05-24 13:12, mcheung63@gmail.com wrote: > Dear All > My proxy server just work in one level forward, That mean vncviewer->my proxy server->vnc server works. > But for two levels forward, vncviewer->my proxy server->my proxy server > vncserver doesn't work, so why? > > public class SimpleProxyServer { > public static void main(String[] args) throws IOException { > try { > String host = "210.5.164.14"; > int remoteport = 5999; > int localport = 1234; I assume your proxies are run on different hosts (so they can both bind to port 1234). Your first proxy connects to port 5999 and the second listens on port 1234. They both connect to the target server. > // Start the client-to-server request thread running > t.start(); > > // Read the server's responses > // and pass them back to the client. > int bytesRead; > try { > while ((bytesRead = streamFromServer.read(reply)) != -1) { > streamToClient.write(reply, 0, bytesRead); > streamToClient.flush(); > } > } catch (IOException e) { > } Here you are blocking accepting new connections. Server-to-client relay should be done in a dedicated thread such as client-to-server. -- Michal