Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2005

Tip: Looking for answers? Try searching our database.

Need help with asynchronous proxy connection

Thread view: 
Bruce Lee - 11 May 2005 17:03 GMT
I need to build a proxy server that will keep alive an asynchronous
connection with a client and a remote server until the client closes. The
type of data is ASCII.

I've tried this code it doesn't work?

//needs to keep client socket & server socket open and wait for messages
from client and returns from server

class CommSession extends Thread{
Socket clie;
Socket serv;
       CommSession(Socket clie,Socket serv){
               this.clie=clie;
               this.serv=serv;
       }

       public void run(){

               try{
               System.out.println("set up session on "+serv);
               while(!clie.isClosed()){
                       DataInputStream in = new
DataInputStream(clie.getInputStream());
                       DataOutputStream out = new
DataOutputStream(serv.getOutputStream());
                       String cmd="";
                       while((cmd=in.readLine())!=null){
                               out.writeBytes(cmd+"\n");
                               System.out.println("TO-SERVER:"+cmd);
                       }

                       DataInputStream in2 = new
DataInputStream(serv.getInputStream());
                       DataOutputStream out2 = new
DataOutputStream(clie.getOutputStream());
                       String cmd2="";
                       while((cmd2=in2.readLine())!=null){
                               out2.writeBytes(cmd2+"\n");
                               System.out.println("TO-CLIENT:"+cmd2);
                       }

               }

               }catch(Exception ss){ss.printStackTrace();}
       }

}
Lee Fesperman - 11 May 2005 19:09 GMT
> I need to build a proxy server that will keep alive an asynchronous
> connection with a client and a remote server until the client closes. The
[quoted text clipped - 44 lines]
>
> }

The isClosed() method for java.net.Socket only tests if you explicitly closed the
socket. It does not test for the other side closing. You need to use the fact that
readLine() returned null to determine of the client closed the socket.

Signature

Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS  (http://www.firstsql.com)



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.