In the previous post, KDE Connect iOS Develop Dairy(1) Build, the build of KDE Connect iOS has been fixed, we can install the application into a device or a simulator.
To connect with the other devices, we need to pair with them. But, before that, the devices need to discover each other with the KDE Connect identity mechanism.
The initial identity process is straightforward, as shown below:
- First, device A will send a UDP broadcast packet, which carries its identity packet;
- Each device B, which receives the UDP broadcast, will try to extract the TCP port information in the packet and try to connect with the device via the port;
- With a TCP connection, each device B will send its identity packet to device A;
- Then, the devices will add a link item to the discovered device list and wait for users’ actions.
With a first attempt, all my devices can find each other, except the iOS one.
In the debug mode, I saw a discover message and an associated output:
"Inoki" uses an old protocol version, this won't work
So, I captured the packets using Wireshark, to see why the old implementation in KDE Connect iOS does not work. The differences are in the packet content and tailored data.
All network packets are generated by serializing
NetWorkPackage class, which is defined in
The properties of that class are:
@property(nonatomic) NSString* _Id;
After the serialization, the content will be a JSON format string. For example, the packet content from KDE Connect iOS is:
And the one from KDE Connect on the other platforms is:
We can see the first difference is about the
id field. In the KDE Connect iOS packet, it is a string. But in the newer version protocol, it is an integer.
So, I changedß its property type from
@property(nonatomic) NSNumber *_Id;
Another significant change is the type and the name of description of capacibilities:
- They were
SupportedIncomingInterfaces, with string type;
- In the latest version, they are
outgoingCapabilities, with array type.
In KDE Connect iOS, it is generated by the following lines in
[np setObject:[[[PluginFactory sharedInstance] getSupportedIncomingInterfaces] componentsJoinedByString:@","] forKey:@"SupportedIncomingInterfaces"];
The returned values are arrays, and a comma string joins them.
So, I changed the key and removed the
[np setObject:[[PluginFactory sharedInstance] getSupportedIncomingInterfaces] forKey:@"incomingCapabilities"];
The protocol version field is defined in the header file:
#define ProtocolVersion 5
I update it to
7 to match the current version.
The tailor data of identity packet from KDE Connect iOS in a Wireshark traffic is
And the one from other KDE Connect versions is
So, I change the line in
- #define LFDATA [NSData dataWithBytes:"\x0D\x0A" length:2]
Finally, the KDE Connect iOS can find the other device and establish connections to them:
On the contrary, the others cannot find KDE Connect iOS client out yet. That’s because the new version requires TLS/SSL after a TCP connection. This will get fixed in the next post.
Good luck to myself!