How do I process datagram data from mergSocket?
Posted: Sat Aug 27, 2016 10:11 pm
I'm writing a simple discovery client/server app using Java (for the server) and a LiveCode app on iOS for the client.
The idea is that the client (iOS) will find it's server on the local lan via a UDP broadcast.
The server responds to a broadcast request just fine and I am able to get a response into LiveCode.
However the data is somehow coded differently to normal strings. It's a form of binary data that some functions struggle to process as a string.
The java code to send the datagram looks like this (sendData is a byte array):
serverSocket.send(new DatagramPacket(sendData, 1024, IPAddress, 9877));
The LiveCode that receives this packet looks like this:
mergSocketAcceptConnections 9877,true
I tried putting the data received into a database using revExecuteSQL, but I get an "Unrecognised token" error returned.
The message at the moment is simply a ip address on the first line, and a port number on the second line. I'll use these two things to create a http connection to the server.
When I try and use the data to make a connection via "get URL data" I get an "unsupported URL" error.
I need to either format the data before sending it from Java or process it after receiving it in LiveCode.
I suspect it could be the fact that the data put into the string is indeed the string I want, plus a lot of "\0" characters padded out to the 1024 byte size of the byte array.
So I guess my question is, how can I format the string that I get back properly?
The idea is that the client (iOS) will find it's server on the local lan via a UDP broadcast.
The server responds to a broadcast request just fine and I am able to get a response into LiveCode.
However the data is somehow coded differently to normal strings. It's a form of binary data that some functions struggle to process as a string.
The java code to send the datagram looks like this (sendData is a byte array):
serverSocket.send(new DatagramPacket(sendData, 1024, IPAddress, 9877));
The LiveCode that receives this packet looks like this:
mergSocketAcceptConnections 9877,true
I tried putting the data received into a database using revExecuteSQL, but I get an "Unrecognised token" error returned.
The message at the moment is simply a ip address on the first line, and a port number on the second line. I'll use these two things to create a http connection to the server.
When I try and use the data to make a connection via "get URL data" I get an "unsupported URL" error.
I need to either format the data before sending it from Java or process it after receiving it in LiveCode.
I suspect it could be the fact that the data put into the string is indeed the string I want, plus a lot of "\0" characters padded out to the 1024 byte size of the byte array.
So I guess my question is, how can I format the string that I get back properly?