public class RouterGroupClient
extends java.lang.Object
Since RouterGroupClient will join the named group automatically when it binds to GroupService, it expose the following simple api:
send(DeviceInfo dest, byte[] msg)
getPeerDevices()
A sample scenario of using RouterGroupClient to interact with GroupService is as following:
//bind to GroupService, join the group named by "groupId" and register GroupHandler //as client side async messaging api for GroupService to call back. mGroupClient = new RouterGroupClient(this, groupId, null, mGroupHandler); mGroupClient.bindService();
//send a message to peers. RotateMsg m = new RotateMsg(RotateMsg.INIT_ORIENT_REQ, 0, 0); //req init orientation mGroupClient.send(null, m.marshall());
//leave group and unbind from GroupService mGroupClient.unbindService();
For detailed tutorial on how to use RouterGroupClient to talk to GroupService and send/receive messages to peers, please check out github sample project.
Modifier and Type | Class and Description |
---|---|
static interface |
RouterGroupClient.GroupHandler
GroupHandler exposes client side async messaging one-way AIDL api to allow GroupService notify
events such as peer devices joining group, peer devices leaving a group or receiving a message.
|
Constructor and Description |
---|
RouterGroupClient(Context c,
java.lang.String grp,
DeviceInfo[] p,
RouterGroupClient.GroupHandler h)
RouterGroupClient constructor; register a GroupHandler to expose client side one-way asynchronous messaging api for GroupService to call back.
|
Modifier and Type | Method and Description |
---|---|
void |
bindService()
bind to Router Group Service.
|
void |
getPeerDevices()
request the info of peer devices in this group;
the response is returned at GroupHandler.onGetPeerDevices().
|
void |
send(DeviceInfo dest,
byte[] msg)
send a message to all peers in a group, or to a specific device.
|
void |
unbindService()
unbind from Router Group Service.
|
public RouterGroupClient(Context c, java.lang.String grp, DeviceInfo[] p, RouterGroupClient.GroupHandler h)
c
- context in which to bind to GroupService.grp
- string name of group.p
- h
- register a GroupHandler to expose client side one-way asynchronous messaging api for GroupService to call back.public void bindService()
public void unbindService()
public void send(DeviceInfo dest, byte[] msg)
dest
- the target device to send message; if set to null, the message is broadcast to all peers in group.msg
- the message to send.public void getPeerDevices()