-
Notifications
You must be signed in to change notification settings - Fork 263
LiveConnectService Component
LiveConnectService
provides a simple zero-configuration communications technology between computers on a network subnet or between programs on a single computer. The underlying technology is multicast DNS (mDNS). Apple popularized this network protocol with their Bonjour product, and Bonjour is currently required to be installed in order for LiveConnectService
to work. For more information about mDNS and Bonjour, see the Wikipedia article Multicast DNS. To install Bonjour, the easiest way is to download and install iTunes. Sony developers with a SHIP account can get the Bonjour installer from \NoDistro\ThirdParty\Wws.LiveConnect
in the wws_atf
directory.
Bonjour allows you to send messages to a single named client or to broadcast messages to a set of clients who have subscribed to a message group, also known as a channel. During its initialization, each Bonjour instance must advertise the groups that can be broadcast to and also subscribe to groups. Advertising allows Bonjour instances to discover each other's groups. Subscribing associates a group with a callback that processes messages to that group.
The LiveConnectService
component's IInitializable.Initialize()
method calls CommonInit()
to initialize Bonjour:
protected void CommonInit()
{
string[] groups = new string[] { AtfGlobalChannel };
Errors error = (Errors)Client.Init(null, groups);
if (error == Errors.LIVECONNECT_SUCCESS)
{
Client.Subscribe(AtfGlobalChannel, GotMessage, null);
}
...
In this code segment, Client
is Wws.LiveConnect.Client
, which is defined in a private library and is a simple wrapper around Bonjour. The Init()
method advertises the single channel AtfGlobalChannel
, available to all LiveConnectService
users.
Assuming Init()
succeeds, it also calls Subscribe()
to subscribe to that channel. LiveConnectService
uses the GotMessage()
callback to trigger a message received event.
LiveConnectService
offers a simple interface to send and receive messages:
-
void Send(string message)
: Broadcast astring
message. -
Send(byte[] bytes)
: Broadcast abyte
array message. -
SendTo(uint senderId, string message)
: Send astring
message to a particular process that previously broadcast a message. The sender ID is from a previous message'sLiveConnectMessageArgs
. -
SendTo(uint senderId, byte[] bytes)
: Send abyte
array message to a particular process that previously broadcast a message. The sender ID is from a previous message'sLiveConnectMessageArgs
. -
event EventHandler<LiveConnectMessageArgs> MessageReceived
: Event for receiving broadcasted messages. This event is triggered by theGotMessage()
callback that was associated with receiving messages broadcast to the channelAtfGlobalChannel
. Message information is placed in aLiveConnectMessageArgs
object.
LiveConnectMessageArgs
provides the following properties and method to access message information:
-
string MessageString
: Get the message as a string. It isnull
if the payload was not sent as a string usingLiveConnectService
. -
byte[] MessageBytes
: Get the message as abyte
array. -
uint SenderId
: Get the sender's ID. This can be used to respond directly to this sender by callingSentTo()
. This ID is typically the hash code, usingFNV1Hash()
, of the sender's name. -
string SenderName
: Get the computer name and port number that sent this message. -
bool CheckMessageId(string id)
: Return whether or not this message's ID matches the givenid
parameter. This may be useful when receiving messages from non-ATF applications that are using Bonjour directly.
FNV1Hash()
is one of the Fowler-Noll-Vo hash functions, which are fast to compute and have a low collision rate.
The AutomationService
component sends and receives messages to any other LiveConnectService
clients, for the purpose of testing LiveConnectService
. The AutomationService
component provides facilities to run an automated script. For more information, see AutomationService Component.
To send a text message, AutomationService
simply calls the LiveConnectService.Send()
method:
{
s_liveConnectService.Send(msg);
}
s_liveConnectService
contains the imported LiveConnectService
object.
AutomationService
subscribes to the LiveConnectService.MessageReceived
event, and its handler gets the message from the LiveConnectMessageArgs
, which GetLastMessage()
retrieves:
s_liveConnectService = m_liveConnectService;
if (s_liveConnectService != null)
s_liveConnectService.MessageReceived += new EventHandler<LiveConnectService.LiveConnectMessageArgs>(s_liveConnectService_MessageReceived);
...
void s_liveConnectService_MessageReceived(object sender, LiveConnectService.LiveConnectMessageArgs e)
{
//For testing purposes we ignore messages from other machines so we don't have to worry
//about messages from other machines interfering with a test
if (e.SenderName.ToLower().Contains(Environment.MachineName.ToLower()))
s_lastMessage = e.MessageString;
}
...
public string GetLastMessage()
{
return s_lastMessage;
}
s_liveConnectService_MessageReceived()
filters the messages, eliminating those not originating on this computer, so that the test isn't accidentally broken by other network activity.
The ATF Timeline Editor Sample uses LiveConnectService
in its TimelineEditor
component to send and receive messages in a very similar way to AutomationService
.
- Home
- Getting Started
- Features & Benefits
- Requirements & Dependencies
- Gallery
- Technology & Samples
- Adoption
- News
- Release Notes
- ATF Community
- Searching Documentation
- Using Documentation
- Videos
- Tutorials
- How To
- Programmer's Guide
- Reference
- Code Samples
- Documentation Files
© 2014-2015, Sony Computer Entertainment America LLC