This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Making a Connection
|
79
instance to which to connect, followed by any number of optional parameters. In
this example, a username and password are supplied after the URI. The connect( )
method returns
false if it detects a malformed URI; otherwise, it returns true, and
Flash attempts to connect to the server.
Not all malformed URIs are caught by the connect( ) method. You
must always make sure the protocol is either
rtmp or rtmpt followed by
a colon; otherwise, the connect( ) method may return
true and then
fail.
The URI can be an absolute URI that includes a hostname or a relative URI that does
not. After the connect( ) method is called, the URI passed into it is available as the
uri property of the NetConnection object.
Absolute URIs
An absolute URI is a string that includes protocol, host, optional port, application
name, and optional instance name segments. The format of an absolute URI is:
rtmp[t]://host[:port]/applicationName[/instanceName]
The parts of the URI in square brackets are optional. An absolute URI contains all
the information needed to identify an application instance to which to connect. The
following sections describe all the parts of an absolute URI.
Protocol
The first part of an absolute URI is the protocol or scheme and must always be speci-
fied as
rtmp, rtmpt,orrtmps, followed by :// for an absolute URI or :/ for a relative
URI. RTMP is preferred because it is the native protocol for FlashCom communica-
tions. Adding the optional t in
rtmpt indicates that HTTP tunneling is to be used.
Tunneling is less efficient, because RTMP messages must be wrapped in HTTP head-
ers, and the server must be constantly polled by the Flash movie. However, tunnel-
ing may successfully make connections through firewalls and proxy servers when
RTMP access fails. Tunneling was first added to Flash Player 6.0.65.0 and Flash-
Com 1.5. When run in a browser, the Flash Player uses the browser to make the
HTTP connections to the server that RTMPT relies on. Since the browser normally
also supports SSL, Macromedia added the ability to use the SSL by specifying the
rtmps protocol instead of rtmpt. When RTMPS is used, the Flash Player attempts to
establish a tunneling connection over HTTPS to FlashCom. Even though FlashCom
1.5 does not support SSL, it is possible to take advantage of RTMPS using additional
server software or specialized network hardware in order to have completely
encrypted real-time communications between Flash movies and FlashCom. Config-
uring a system to accept SSL connections is briefly discussed in Chapter 18 and at:
http://www.macromedia.com/devnet/mx/flashcom/articles/firewalls_proxy04.html

Get Programming Flash Communication Server now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.