Union on port 80

Added by Casey Foster 788 days ago

I've been messing around with the union.xml file trying to add a gateway for port 80, but I'm not exactly sure what I'm doing =p Ideally my server will be able to run the xml socket connection on port 9100 and http connection on port 80, like tryunion.com does (I believe).

Does anyone have an example of configuration files with union set up to run on both ports 9100 and 80? And is there any other configuration besides in the union.xml that needs to be done for this to work?

Thanks,
-Casey


Replies

RE: Union on port 80 - Added by derek clayton 787 days ago

With Union when using an NIO gateway you don't have to listen on different ports to accept different types of connections. By default any single port will accept both types of connections and Reactor will attempt a persistent XML socket connection first and if that fails it will attempt to make an HTTP connection.

Here's an example of setting up two NIO gateways on 9100 and 80.

union.xml

  <gateways>
    <gateway id="NIOPort80" type="flash:nio">
      <port>80</port>
      <policy_file>policy.xml</policy_file>
    </gateway>  

    <gateway id="NIOPort9100" type="flash:nio">
      <port>9100</port>
      <policy_file>policy.xml</policy_file>
    </gateway>                 
  </gateways>

This is all you need to configure on the server. In Reactor you'll want to specify the ports in your connect method for example:

  reactor = new Reactor();
  reactor.addEventListener(ReactorEvent.READY, readyListener);
  reactor.connect("tryunion.com", 80, 9100);

Reactor will then try to connect as follows:

1) XML persistent connection on port 80.
2) If 1 fails, try an XML persistent connection on port 9100.
3) If 2 fails, try an HTTP connection on port 80.
4) If 3 fails, try an HTTP connection on port 9100.

By default, Reactor will exhaust all potential means of establishing a persistent socket connection before resorting to an HTTP connection. HTTP connections are less responsive than persistent socket connections, but have a higher chance of connecting from behind a firewall.

If you want a different connection order, you can fully customize the connection order via Reactor's ConnectionManager.

In the Admin Gateways tab you'll be able to see the gateways deployed and statistics about what's connecting to them.

As mentioned the HTTP connection (and automatic Reactor fail over) only works for NIO gateways which is the recommended gateway for internet connections. The old "2 thread per client" gateway ("flash:io") is still available but we may discontinue including it by the 1.0 release.

Cheers,

Derek

RE: Union on port 80 - Added by Casey Foster 787 days ago

Thanks for the quick reply!

I added the port 80 gateway as in your example but I seem to have run into a permission problem. I've been using chmod 775 * in the union root directory, is there something else I need to give permissions to?

2009-12-08 16:56:16,791 WARN  - *****************************************************
2009-12-08 16:56:16,792 WARN  - *** Starting Union Server Alpha 1.0.0 (build 325) ***
2009-12-08 16:56:16,792 WARN  - *****************************************************
2009-12-08 16:56:16,792 WARN  - UPC Version: 1.4.1
2009-12-08 16:56:16,871 WARN  - Using CharSet [UTF-8]
2009-12-08 16:56:16,898 WARN  - UNION_HOME set to [/Applications/union/.]
2009-12-08 16:56:16,992 WARN  - Gateway [NIOGateway9100] bound to port [9100] on all local IP addresses.
2009-12-08 16:56:16,993 INFO  - Gateway [NIOGateway9100] added to the Server.
2009-12-08 16:56:16,996 ERROR - Error binding address for NIO Gateway [NIOGateway80]
java.net.SocketException: Permission denied
    at sun.nio.ch.Net.bind(Native Method)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
    at org.apache.mina.transport.socket.nio.NioSocketAcceptor.open(NioSocketAcceptor.java:251)
    at org.apache.mina.transport.socket.nio.NioSocketAcceptor.open(NioSocketAcceptor.java:48)
    at org.apache.mina.core.polling.AbstractPollingIoAcceptor.registerHandles(AbstractPollingIoAcceptor.java:523)
    at org.apache.mina.core.polling.AbstractPollingIoAcceptor.access$200(AbstractPollingIoAcceptor.java:65)
    at org.apache.mina.core.polling.AbstractPollingIoAcceptor$Acceptor.run(AbstractPollingIoAcceptor.java:407)
    at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:637)
2009-12-08 16:56:16,997 INFO  - Gateway [NIOGateway80] added to the Server.
2009-12-08 16:56:16,998 INFO  - Loaded module type [class] with code [net.user1.union.servermodule.ServerStatsServerModule]
2009-12-08 16:56:16,998 WARN  - Server module [serverStatsServerModule] loaded.
2009-12-08 16:56:17,000 WARN  - POLICY_FILE attribute missing for Gateway [_ADMIN_GATEWAY_].  Using default [policy.xml].
2009-12-08 16:56:17,003 WARN  - Gateway [_ADMIN_GATEWAY_] bound to port [9110] on all local IP addresses.

Let me know if you need more info from the logs or anywhere else if that will help.

Thanks,
-Casey

BTW
I'm running OS X 10.6.2
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04-248-10M3025)

RE: Union on port 80 - Added by colin moock 787 days ago

you need to run the server as root to bind to ports under 1024.

colin

RE: Union on port 80 - Added by Casey Foster 787 days ago

Ah thanks, that was it.
sudo ./startserver.sh

And now it's working =)

-Casey