public class RouterConnectionClient
extends java.lang.Object
It exposes the following groups of methods in accordance with ConnectionService AIDL api:
void getNetworks() void getActiveNetwork() void connectNetwork(NetInfo net) void disconnectNetwork(NetInfo net) void activateNetwork(NetInfo net)
void startPeerSearch(DeviceInfo groupLeader, int timeout) void stopPeerSearch()
void acceptConnection(DeviceInfo peer) void connect(DeviceInfo peerInfo, byte[] token, int timeout) void denyConnection(DeviceInfo peer, int rejectCode) void disconnect(DeviceInfo peerInfo)
void setConnectionInfo(String devName, boolean useSSL, int liveTime,getDeviceInfo() int connTime, int searchTime) void getConnectionInfo() void getDeviceInfo() void getPeerDevices()
A sample scenario of using RouterConnectionClient to interact with ConnectionService is as following:
//first bind to Router ConnectionService, and register ConnectionHandler. connClient = new RouterConnectionClient(this, connHandler); connClient.bindService();
connClient.connect(device, securityToken.getBytes(), connTimeout);
connClient.unbindService();
For detailed tutorial on how to use RouterConnectionClient to talk to ConnectionService and set up peer device connections, please check out github sample project.
Modifier and Type | Class and Description |
---|---|
static interface |
RouterConnectionClient.ConnectionHandler
ConnectionHandler exposes client side async messaging one-way AIDL api to allow ConnectionService call back to
notify events such as network attachment and detachment, device connection and disconnection.
|
Constructor and Description |
---|
RouterConnectionClient(Context c,
RouterConnectionClient.ConnectionHandler h)
RouterConnectionClient constructor; register a ConnectionHandler to expose client side one-way asynchronous messaging api for ConnectionService to call back.
|
Modifier and Type | Method and Description |
---|---|
void |
acceptConnection(DeviceInfo peer)
accept the connection request from a peer device.
|
void |
activateNetwork(NetInfo net)
choose network as the network used to connect peer devices hereafter.
|
void |
bindService()
bind to Router Connection Service.
|
void |
connect(DeviceInfo peerInfo,
byte[] token,
int timeout)
send connection request to peer device.
|
void |
connectNetwork(NetInfo net)
connect to the specified network.
|
void |
denyConnection(DeviceInfo peer,
int rejectCode)
deny the connection request from a peer device and tell the reason.
|
void |
disconnect(DeviceInfo peerInfo)
disconnect a connected peer device.
|
void |
disconnectNetwork(NetInfo net)
disconnect from specified network.
|
void |
getActiveNetwork()
request info of the network currently used to connect peer devices.
|
void |
getConnectionInfo()
request current connection related parameters at Connection Service.
|
void |
getDeviceInfo()
request current device info (name, address, port) known at Connection Service.
|
void |
getNetworks()
retrieve info of attached networks;
the response is returned at ConnectionHandler.onGetNetworks().
|
void |
getPeerDevices()
retrieve info of connected peer devices;
the response is returned at ConnectionHandler.onGetPeerDevices().
|
void |
setConnectionInfo(java.lang.String devName,
boolean useSSL,
int liveTime,
int connTime,
int searchTime)
set connection related parameters at Connection Service; they will be used as default hereafter.
|
void |
startPeerSearch(DeviceInfo groupLeader,
int timeout)
start a new search session to find peer devices.
|
void |
stopPeerSearch()
stop current search session.
|
void |
unbindService()
unbind from Router Connection Service.
|
public RouterConnectionClient(Context c, RouterConnectionClient.ConnectionHandler h)
c
- context (activity or service) in which to bind to Connection Service.h
- register a ConnectionHandler to allow ConnectionService call back.public void bindService()
public void unbindService()
public void startPeerSearch(DeviceInfo groupLeader, int timeout)
groupLeader
- info of leader device which may run hotspot or own wifi
direct group. It is the enabler for a group of devices
to discover each other.timeout
- search session timeout in seconds; if set to 0, search forever until
stopped explicitly; if set to negative, use preset search timeout (default 30 seconds).public void stopPeerSearch()
public void acceptConnection(DeviceInfo peer)
peer
- info of connecting peer device.public void denyConnection(DeviceInfo peer, int rejectCode)
peer
- info of connecting peer device.rejectCode
- reason of denial.public void connect(DeviceInfo peerInfo, byte[] token, int timeout)
peerInfo
- info of peer device.token
- binary data for authentication.timeout
- connection timeout in seconds; if set to 0, wait forever;
if set to negative, use preset value (default to 5 seconds).public void disconnect(DeviceInfo peerInfo)
peerInfo
- info of device to be disconnected.public void setConnectionInfo(java.lang.String devName, boolean useSSL, int liveTime, int connTime, int searchTime)
devName
- name of this device appearing to peers.useSSL
- if use TLS/SSL for peer connections.liveTime
- the period between successive verifications of peer devices aliveness.connTime
- socket connection attempt timeout.searchTime
- peer device search timeout.public void getConnectionInfo()
public void getDeviceInfo()
public void getPeerDevices()
public void getNetworks()
public void getActiveNetwork()
public void activateNetwork(NetInfo net)
net
- info of the network to be activated.public void connectNetwork(NetInfo net)
net
- info of the network to be activated.public void disconnectNetwork(NetInfo net)
net
- info of the network to be activated.