Results 1 to 3 of 3
  1. #1
    stpeln is offline Member
    Join Date
    Oct 2011
    Posts
    1
    Rep Power
    0

    Default Several instances of the same application on a terminal server - localhost problem

    Hi!

    Background:
    I am maintaining a Java application where I create a http server (using the class org.apache.http.protocol.HttpService). The http server creates a socket on port 6060. From an Ajax script executed in a browser on the same machine, a xmlhttp request is sent to localthost port 6060. The request is transmitted to the Java application and and response is sent, works fine. As long as the solution is executed on a client machine (desktop computer). The Java application executes in ONE instance since it is ONE machine with ONE user. The application is designed to handle requests from one user only.

    Problem:
    When the solution is executed on a terminal server (through Windows Remote Desktop Connection), each user will start a new instance of the Java application, that is if there are five users logged in the the terminal server, there will be five running instances of the Java application. The first started instance allocates port 6060 on localhost. But when the following instances tries to allocate port 6060 on localhost, it fails since it is already allocated by the first instance.

    I expected this to work, since I thought that each user on a terminal server executed in a own session with a memory and ports of its own, but obviously this is not the case. I have however heard that it should be possible to allocate a "virtual" port (i.e. unique for my session) instead of a machine physical port.

    Does anyone have a clue about how to solve this, I am in urgent need of advises...

    I insert parts of my Java code where I create the http server:

    Java Code:
    ServerSocket mSocket = new ServerSocket( 6060);
    HttpParams mHttpParams = new SyncBasicHttpParams();
    mHttpParams
            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, DEFAULT_TIMOUT )
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, DEFAULT_BUFFER_SIZE )
            .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false )
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true )
            .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1")
            .setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");
    
    // Set up the HTTP protocol processor
    HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
                    new ResponseDate(),
                    new ResponseServer(),
                    new ResponseContent(),
                    new ResponseConnControl()
            });
    
    // Set up request handlers
    HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("*", new GadgetRequestHandler( mGadgetIntegrator ));
            
    // Set up the HTTP 
    HttpService mService = new HttpService(
    httpproc, 
    new DefaultConnectionReuseStrategy(), 
    new DefaultHttpResponseFactory(),
    reqistry,
    mHttpParams);
    Thanks!

  2. #2
    Grkn is offline Member
    Join Date
    Oct 2011
    Posts
    65
    Rep Power
    0

    Default Re: Several instances of the same application on a terminal server - localhost proble

    I understand the problem. I can only give advice to you.

    You can not open 2 server in a specific port in same machine.
    There several ways:
    First one: Open server in a different java program so each user do not try to open server for each instance.
    Second: If your program is not so heavy then you can use synchronization. Just wait one user to finish his job. You can make it in file :)

    Of course first one is the best way.
    //ServerSocket mSocket=new ServerSocket(6060); this code must be instanced once.

  3. #3
    Grkn is offline Member
    Join Date
    Oct 2011
    Posts
    65
    Rep Power
    0

    Default Re: Several instances of the same application on a terminal server - localhost proble

    If you want to use second choice then don forget to close server each time.

Similar Threads

  1. Replies: 2
    Last Post: 09-24-2011, 08:53 AM
  2. How to test my proxy application on localhost?
    By ragnonerodocet in forum Java Servlet
    Replies: 2
    Last Post: 04-18-2011, 10:15 AM
  3. jboss server, localhost as ip...
    By Sno in forum Eclipse
    Replies: 1
    Last Post: 06-23-2010, 08:30 PM
  4. Replies: 2
    Last Post: 04-02-2010, 01:47 PM
  5. Ping a server when server is not in the localhost..
    By kshitiz in forum New To Java
    Replies: 1
    Last Post: 03-19-2009, 09:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •