Getting Started > Connecting to the server > Opening a connection to the server

 

Opening a connection to the server

Open a new file in the Flash authoring environment, and then add the client-side ActionScript commands to connect to the server.

 
To connect to Flash Communication Server:

1

In a new Flash movie, begin opening a connection by issuing the following command:

my_nc = new NetConnection();

2

Follow this command with a connect command:

my_nc.connect(targetURI);

In this basic syntax for NetConnection.connect (omitting optional parameters), targetURI is the Uniform Resource Identifier (URI) of an application on the Flash Communication Server that should run when the connection is made. To specify targetURI, use one of the following formats (items in brackets are optional):

rtmp://localhost[:port]/appName[/instanceName] (The use of localhost indicates that the server is running on your local computer)


rtmp://host[:port]/appName[/instanceName] 

Note that in all syntax examples for targetURI, you must specify rtmp (the Real-Time Messaging Protocol) as the protocol for the connection. If you omit it, the Flash Player assumes you want to make an HTTP connection to an application server, and your connection will fail.

If you want to connect to a virtual host other than the default virtual host, specify the virtual host's name in host. If the server is running on your local machine, you can use "localhost" as the host name in the URI; this is often convenient during application development.

For example, the following code uses the new NetConnection constructor to create a new connection object. Then, the object is connected to the server with the call to my_nc.connect.

// Makes a new connection object
my_nc = new NetConnection();
	
// Connects to the instance named appInstance 
// of the application named appName
// located on the Flash Communication Server 
// that is running on the virtual host myServer.myDomain.com
my_nc.connect("rtmp://myServer.myDomain.com/appName/appInstance");