use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class LanLinkProvider method udpPacketReceived.
// I've received their broadcast and should connect to their TCP socket and send my identity.
private void udpPacketReceived(DatagramPacket packet) {
final InetAddress address = packet.getAddress();
try {
String message = new String(packet.getData(), Charsets.UTF_8);
final NetworkPacket identityPacket = NetworkPacket.unserialize(message);
final String deviceId = identityPacket.getString("deviceId");
if (!identityPacket.getType().equals(NetworkPacket.PACKET_TYPE_IDENTITY)) {
Log.e("KDE/LanLinkProvider", "Expecting an UDP identity packet");
return;
} else {
String myId = DeviceHelper.getDeviceId(context);
if (deviceId.equals(myId)) {
// Ignore my own broadcast
return;
}
}
Log.i("KDE/LanLinkProvider", "Broadcast identity packet received from " + identityPacket.getString("deviceName"));
int tcpPort = identityPacket.getInt("tcpPort", MIN_PORT);
SocketFactory socketFactory = SocketFactory.getDefault();
Socket socket = socketFactory.createSocket(address, tcpPort);
configureSocket(socket);
OutputStream out = socket.getOutputStream();
NetworkPacket myIdentity = NetworkPacket.createIdentityPacket(context);
out.write(myIdentity.serialize().getBytes());
out.flush();
identityPacketReceived(identityPacket, socket, LanLink.ConnectionStarted.Remotely);
} catch (Exception e) {
Log.e("KDE/LanLinkProvider", "Cannot connect to " + address, e);
if (!reverseConnectionBlackList.contains(address)) {
Log.w("KDE/LanLinkProvider", "Blacklisting " + address);
reverseConnectionBlackList.add(address);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
reverseConnectionBlackList.remove(address);
}
}, 5 * 1000);
// Try to cause a reverse connection
onNetworkChange();
}
}
}
use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class LanLinkProvider method tcpPacketReceived.
// They received my UDP broadcast and are connecting to me. The first thing they sned should be their identity.
private void tcpPacketReceived(Socket socket) {
NetworkPacket networkPacket;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String message = reader.readLine();
networkPacket = NetworkPacket.unserialize(message);
// Log.e("TcpListener","Received TCP package: "+networkPacket.serialize());
} catch (Exception e) {
Log.e("KDE/LanLinkProvider", "Exception while receiving TCP packet", e);
return;
}
if (!networkPacket.getType().equals(NetworkPacket.PACKET_TYPE_IDENTITY)) {
Log.e("KDE/LanLinkProvider", "Expecting an identity packet instead of " + networkPacket.getType());
return;
}
Log.i("KDE/LanLinkProvider", "identity packet received from a TCP connection from " + networkPacket.getString("deviceName"));
identityPacketReceived(networkPacket, socket, LanLink.ConnectionStarted.Locally);
}
use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class ClipboardPlugin method propagateClipboard.
void propagateClipboard(String content) {
NetworkPacket np = new NetworkPacket(ClipboardPlugin.PACKET_TYPE_CLIPBOARD);
np.set("content", content);
device.sendPacket(np);
}
use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class LanPairingHandler method unpair.
@Override
public void unpair() {
mPairStatus = PairStatus.NotPaired;
NetworkPacket np = new NetworkPacket(NetworkPacket.PACKET_TYPE_PAIR);
np.set("pair", false);
mDevice.sendPacket(np);
}
use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class LanPairingHandler method rejectPairing.
@Override
public void rejectPairing() {
hidePairingNotification();
mPairStatus = PairStatus.NotPaired;
NetworkPacket np = new NetworkPacket(NetworkPacket.PACKET_TYPE_PAIR);
np.set("pair", false);
mDevice.sendPacket(np);
}
Aggregations