[Main] [News] [Publications] [Downloads] [Documents] [Contacts]


Documents

Communicating with XfacePlayer over network

XfacePlayer has a built in support for control over network using TCP/IP. Clients written in C/C++, Java, ActionScript (Flash) can connect and communicate with XfacePlayer. All the messaging is implemented using strings in XML syntax.

Various tasks are already implemented and others can be inserted by deriving and reimplementing some classes. See XfaceApp::Task and XfaceApp::TaskDictionary in Xface documentation for more details. Everytime a task is sent to server, some acknowledgement notification is sent back by the server.

Connecting

We can first try connecting, and playing the content.. In XfacePlayer, you can start the server using the traffic light or from command line with -s parameter. Before that you can modify the listening port from the menu. default port is 50011.

After you successfully connect using tcp/ip, you immediately get your first notification: CONNECTION_OK, containing your ownerID (client ID) which you should use throughout your session with the server. The notification is in string as below.

<notify name="CONNECTION_OK" ownerId="42" taskId="0" status="0">

Let's see what this XML says:
name: usually the task name that you sent is sent back. Only exception is CONNECTION_OK.
ownerID: use this client ID for further communication with the server. as explained below.

taskId: corresponds to the task you hashed and sent (not important (0) for connection notification)
status: see possible status messages and their meanings in XfaceApp::Notification documentation.

Above notification means you connected with client ID 42 successfully, keep that ID somewhere safe, you'll need it later on.

Sending Tasks

Let's send a task that says start playback whatever you have. Create a string as follows;

<task name="RESUME_PLAYBACK" ownerId="42" taskId="420001" status="0">

or use XfaceApp::Task class (if you use C++ with Xface code installed) as follows;

XFaceApp::Task task("RESUME_PLAYBACK",m_clientId,++m_taskCount+100000*m_clientId);

Let's see what this XML says:
name: name of the task, see XfaceApp::TaskDictionary for available task names and their brief explanations.
ownerID: Unique (!!) ID representing the client. Alternatively, you can just use 0, as an identifier, if you don't care about acknowledgements at all. If ID is 0, no notification is sent for the tasks. This ID will be handy if one day we need more than one clients connecting to the face.
taskID: give an ID to all tasks you send, so that you can match the notification (acknowledgement) properly.
param: contains the string passed as a parameter. Can signify the name of a FAP/WAV/FDP file to load and its path, or something else... Not used in the above script.

Notifications

For the above task, you get 3 notification messages in XML as follows;

<notify name="RESUME_PLAYBACK" ownerId="42" taskId="420001" status="1">

<notify name="RESUME_PLAYBACK" ownerId="42" taskId="420001" status="2">

<notify name="RESUME_PLAYBACK" ownerId="42" taskId="420001" status="3">

which says;

  1. your RESUME_PLAYBACK task is received and queued successfully.

  2. XfacePlayer started to playback (status = 2).

  3. XfacePlayer ended playback (status = 3).

Sample Applications

There are two sample implementations for the client in Xface codebase, wxFaceClientSimple is the simplest of the two while wxFaceClient implements all the messaging features.