XML over Socket

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

XML over Socket

Post by DavJans » Thu Apr 24, 2014 11:08 pm

I'm trying to interface my app with another program, and I have gotten some information from the other programs developer, Can anyone point me in the right direction for information that will make this happen.

Here is some info I got from the other software developer, if it helps you help me :)

That's not a problem, essentially what we will do is send commands to the back-end service through a TCP socket. Some quick searching came up with this link http://lessons.runrev.com/s/lessons/m/4 ... ng-sockets which appears to show how to use a client TCP socket.

There is a little more work with this method because there is a message format that the XML command needs to be put into:

- The first 10 bytes is for the length of the XML command (excluding the 74 header bytes). If your command is 200 bytes long then this should be 0000000200. Note the 0's here are actually the character '0', ASCII code 48.

- The next byte should be an uppercase N. This is the compression format, N means that neither the request or response XML will be compressed.

- The next 63 bytes should be the ASCII code 0. These are placeholders in the message format for future-use options.

- The rest of the message is the actual XML command.


The response comes back in the same format. Read the first 10 bytes for the length of the response XML. You can ignore the next 64 bytes, then read the response XML.

The remote server (back-end service) runs on the server on port 9154. Give it a whirl and let me know if you have any problems or questions.


Connecting through the remote server also changes a couple aspects of how the commands needs to be executed.

- Use the ConnectRemote command to connect instead of Connect:

<FabSuiteXMLRequest>
<ConnectRemote>
<Username>user</Username>
<Password>pass</Password>
</ConnectRemoate>
</FabSuiteXMLRequest>

If successful, the response will include a ConnectionGUID element. The remote server processes commands from all users logged into remote link so the ConnectionGUID needs to be passed to each subsequent command to identify your session:

<FabSuiteXMLRequest>
<ConnectionGUID>guid returned by ConnectRemote response</ConnectionGUID>
<GetInventorySummary>
...
</GetInventorySummary>
</FabSuiteXMLRequest>
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: XML over Socket

Post by BvG » Fri Apr 25, 2014 9:49 am

You didn't really ask any question :P

Here's some general information in the dictionary which you can read:

open socket
read from socket
write to socket

here's some basic socket examples:
http://livecodeshare.runrev.com/stack/5 ... ket-server
http://livecodeshare.runrev.com/stack/5 ... ket-client
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: XML over Socket

Post by DavJans » Fri Apr 25, 2014 4:10 pm

I kinda did, first line, but you answered it just fine even if you missed it. Just looking for information at this point, I have never worked with sockets or xml, and so I'm trying to learn both at the same time :) I will read threw what you posted, Thank you.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: XML over Socket

Post by DavJans » Thu May 15, 2014 4:54 pm

After playing with this for a few weeks now, I realize that I'm too stupid to figure it out on my own.

So far, I can open a socket. I know this because when I try to open it twice I do get a response that tells me the socket is already open. other than that I have not been able to get any other anything from my server, or I don't know how to put a response into a field for me to read.

Another thing I read over was "Converting between characters and numerical (ASCII) values" which I'm struggling to understand.

Here is another email I got from support from the program I'm trying to interface with, which is what lead me to the 'Converting between characters and numerical (ASCII) values" page,
In the first part with the length of the message (0000000167) the 0's should be the digit 0 (ascii code 48 - http://www.asciitable.com/). The ones after the letter N need to be null characters, ascii code 0.
This page looks like it may be helpful in handling the ascii code 0: http://lessons.runrev.com/s/3527/m/2592 ... cii-values
I have another example of a request and a response from the software that I'm trying to talk to as well but its written in Visual C# and I don't know how to read it.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: XML over Socket

Post by AxWald » Fri May 16, 2014 1:55 pm

Hi DavJans,

when looking at the above linked lesson check the lower part, the "chat server". This is a great example and helped me a lot when building my own socket server.
For your convenience I attached my test-client. It's a bit specialized, but should show you how it's done.
Be sure to adjust the port in the stack script (and read it carefully!), and create an entry for the server to connect to. The remaining should be self-explanatory.

The real problem I see is the composition of the actual datagram on byte level. Especially "ASCII code 0" makes me shiver, reminiscences of good old times - it used to be the closing delimiter for strings and such ...
Maybe someone other can help here? I just don't know, don't do such things anymore.

Hope I could help a bit. Feel free to ask questions :)

Have a good time!

Axel

Edit: Anybody wrote a HexEditor yet, in LC? This could come handy here ...

Edit 2: Just did some tests - numToChar(0) seems to work:

put "Blob" & numtochar(0) & "Blub"
-> Blob Blub (can't insert here, but looks this way in the msg box)

put chartonum(numtochar(0)) && "Blob" & numtochar(0) & "Blub"
-> 0 Blob Blub (same as above, seems it's a real char(0))
Attachments
AWA_SSD_Testclient.zip
A test client to demonstrate communication to a socket server
(4.7 KiB) Downloaded 295 times
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Post Reply