In the previous post, KDE Connect iOS Develop Dairy(1) Build, the build of KDE Connect iOS has been fixed, the application can be installed into a device or a simulator.
To connect with the other devices, we need to pair with them. But, before that, the devices need discover each other with the KDE Connect identity mechanism.
The initial identity process is really simple, as shown below:
- First, a 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 own identity packet to the device A;
- Then the devices will add a link item to the discovered device list, and wait the users’ actions.
With a first attemp, all my devices can find each other, except the iOS one.
In the debug mode, I saw discover message and an output associated:
"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 doesn’t work. The differences are in the packet content and the tailor data.
All network packets are generated by serilizing
NetWorkPackage class, which is defined in
The properties of that class are:
@property(nonatomic) NSString* _Id;
After the serilization, 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 platforme is:
We can see the first difference is about the
id field. In the KDE Connect iOS packet, it’s a string. But in the newer version protocol, it’s an integer.
So, I change its property type from
@property(nonatomic) NSNumber *_Id;
Another big 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’s generated by the following lines in
[np setObject:[[[PluginFactory sharedInstance] getSupportedIncomingInterfaces] componentsJoinedByString:@","] forKey:@"SupportedIncomingInterfaces"];
Obviously, the returned values are arrays, but they are joined by a comma string.
So, I just change the key string, and remove 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 are
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 the 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 connnection. This will get fixed in the next post.
Good luck to myself!