Reactor Chat Tutorial, Part 1

Connecting to Union Server

Every Union application starts with a connection to the Union server, which is typically made with a Reactor object. Here's the code, with changes highlighted:

package {
  import flash.display.Sprite;

  // Import the Reactor class
  import net.user1.reactor.Reactor;

  public class UnionChatPart1 {
    // Define a variable to reference the Reactor object
    protected var reactor:Reactor;

    public function UnionChatPart1 () {
      // Make the Reactor object
      reactor = new Reactor();
      // Connect to the server
      reactor.connect("tryunion.com", 80);
    }
  }
}

If you compile and run the preceding code, you'll see a connection log in the Output window (Flash) or the debug Console (Flex Builder/Flash Builder). Notice that Reactor automatically attempts to connect over a persistent TCP/IP socket, but also creates a failover HTTP connection that is used if the socket connection is blocked by a firewall. The socket connection and the HTTP connection run over the same port (80 in this case); no special configuration is required to connect to Union over HTTP.

Pages: 1 2 3 4 5 6 7