3 Replies Latest reply on Apr 23, 2007 2:54 AM by Ron Sigal

    MasterServerSocket with VirtualServerSocket

    Lukasz Matuszczak Newbie

      Hi,

      I have a problem with use of multiplexing sockets API. I have an application which consists of many clients connected server to a server by TCP. The application uses a third-party library which creates far too many TCP connections. I can't change the library, but I can change socket factories which are used by the library.

      My idea is to have one physical Socket and many VirtualSockets on the client side, and VirtualServerSocket somehow bound to MasterServerSocket on the server side. I don't need any VirtualSockets from server connecting to VirtualServerSockets on the client side. I tried to adapt Symmetric Scenario for my needs but I don't understand two things.

      - Do I have to create VirtualServerSocket on the client side although I don't need any "callbacks", i.e. VirtualSockets on the server connecting explicitly to clients?
      - How to allow multiple physical clients to connect to one MasterServerSocket?
      MasterServerSocket has the acceptServerSocketConnection() method. But it returns only server port, so how could I create newly created VirtualServerSocket with the concrete client bound. Or is it possible to have one VirtualServerSocket accepting connections from many physical connections?

      Thanks in advance
      Lukasz

        • 1. Re: MasterServerSocket with VirtualServerSocket
          Ron Sigal Master

          Hi,

          Here is how multiplex works with respect to server sockets. The MasterServerSocket wraps a real server socket, and when a client connects to it (the first time) by calling a VirtualSocket constructor targeted at the MasterServerSocket, the MasterServerSocket creates a real socket and creates a VirtualSocket associated with that socket. This is how a multiplex connection is created from the client to the server.

          Let's call the multiplex connection MC. Now, you can attach a VirtualServerSocket to either end of MC, which allows new virtual connections to be added to MC. To attach a VirtualServerSocket to the server side, you need to take an existing VirtualSocket associated with MC and pass it to the constructor

          public VirtualServerSocket(VirtualSocket socket, Map configuration) throws IOException
          


          Then the VirtualServerSocket will be bound to the same host and port as the MasterServerSocket, and subsequent connections to that host and port from the other end of MC will be handled by the VirtualServerSocket. That is, new virtual connections will be added to the single physical connection. You can see this idea at work in MultiplexServerInvoker.run().

          In your situation it sounds like you are restricted to configuring your third party library with a server socket factory, and the existing VirtualServerSocketFactory probably won't work for you, since it was intended for other purposes. However, you could write your own. Initialize it with a VirtualSocket and then in each createServerSocket() method call the VirtualServerSocket constructor shown above.


          - Do I have to create VirtualServerSocket on the client side although I don't need any "callbacks", i.e. VirtualSockets on the server connecting explicitly to clients?


          No. You would need a VirtualServerSocket on the client side only if you intended to create virtual connections from the server to the client.


          - How to allow multiple physical clients to connect to one MasterServerSocket?


          That is enabled automatically, since the MasterServerSocket wraps a real server socket.

          • 2. Re: MasterServerSocket with VirtualServerSocket
            Lukasz Matuszczak Newbie

            Hi,

            Thank you very much for your answer. It works! I have another two questions:
            - What kind of configuration can be passed into VirtualServerSocket constructor you mentioned? (Now i pass null :))
            - Let's suppose I have 100 physical connections from 100 different clients. I want to react if there is a new virtual connection on any of VirtualServerSockets bound to these physical connections or if there is a new physical connection. The only idea is to have 101 threads, 100 waiting on accept() on the VirtualServerSockets, and one waiting on accept() on the MasterServerSocket. I'd like to have a kind of listener on VirtualServerSockets to observe new coming connections without blocking. I would use NIO, but I doubt it will work with VirtualServerSocket.
            Without using virtual sockets I can have only one thread waiting on one real ServerSocket.accept() method (but I have far too many connections :).

            • 3. Re: MasterServerSocket with VirtualServerSocket
              Ron Sigal Master

               


              What kind of configuration can be passed into VirtualServerSocket constructor you mentioned?


              In the normal course of events, this configuration map would be the one that the Connector is configured with.


              I'd like to have a kind of listener on VirtualServerSockets to observe new coming connections without blocking.


              I see, you want a kind of "virtual Selector". The multiplex transport doesn't have that facility. An NIO-like virtual socket would be a nice project, but I don't think there will be much of a demand for it. Of course, if you are interesting in contributing to the Remoting project, you would certainly be welcome.