Af2NetConnection.connect - affluxis/csjava GitHub Wiki
Usage
myConnection.connect(targetURI [, parameters])
Parameters
targetURI - The Uniform Resource Identifier (URI) of the application on the server that should run when the connection is made. To specify targetURI, use the following format (items in brackets are optional): subdomain.domain.com/appName[/instanceName], subdomain.domain.com/sharedWhiteboardApp/June2002.
parameters - Optional parameters of byte[] object type to be passed to the application specified in targetURI.
Returns
A Boolean value of true if you passed in a valid URI, false otherwise. (To determine if the connection was successfully completed, use Af2NetConnection.onStatus).
Description
Method; connects to an application instance on the server. If you want to use this connection for publishing or playing audio or video in real time, or to publish or play previously recorded audio or video streams, you must connect to the server and then create a Af2NetStream object within this Af2NetConnection object. For more information, see the 'Af2NetStream (object)' entry. If you want to use this connection for synchronizing data among multiple clients or between the client and a server, you must connect to the server and then create a remote shared object within this Af2NetConnection object. For more information, see the “Af2SharedObject (object)” entry. When you call this method, the Af2NetConnection.onStatus event handler is invoked with an information object that specifies whether the connection succeeded or failed. For more information, see the example below and Af2NetConnection.onStatus. If the connection is successful, Af2NetConnection.isConnected is set to true. Because of network and thread timing issues, it is better to place a Af2NetConnection.onStatus handler in a script before a Af2NetConnection.connect method. Otherwise, the connection might complete before the script executes the onStatus handler initialization. Also, all security checks are made within the connect method, and notifications will be lost if the onStatus handler is not yet set up. If the specified connection is already open when you call this method, an implicit Af2NetConnection.close method is invoked, and then the connection is reopened. Video and audio are not queued during the connection process. Any video or audio that is streaming from the server is ignored until the connection is successfully completed. For example, confirm that the connection was successful before enabling a button that calls the Af2NetStream.publish method. If your connection fails, make sure you have met all the requirements for connecting successfully:
- You are connecting to a valid application on the correct server.
- You have a subdirectory in the application directory with the same name as the application.
- The server is running.
To distinguish among different instances of a single application, pass a value for instanceName as part of targetURI. For example, you may want to give different groups of people access to the same application without having them interact with each other. To do so, you can open multiple chat rooms at the same time, as shown below.
nc.connect("subdomain.domain.com/chatApp/peopleWhoSew");
nc.connect("subdomain.domain.com/chatApp/peopleWhoKnit");
Example
The following example connects to the funAndGames application on the server.
con = new Af2NetConnection(activity);
con.connect("subdomain.domain.com/funAndGames");