Sending XML data over a Socket Connection - CasparCG

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
aircooled76
Posts: 38
Joined: Mon May 20, 2013 3:14 pm

Sending XML data over a Socket Connection - CasparCG

Post by aircooled76 » Mon May 20, 2013 3:54 pm

Hi Guys,

Just writing a CasparCG video basketball scoreboard control application with LiveCode... first off I love it..... and I am a convert, easy to use and powerfull...

So... in a nutshell the CasparCG video playout server incorporates a flash player that can update the information in a Flash Template scoreboard on the fly, updating Team 1's Score etc... creating an awesome scoreboard that I can overlay over my videos!

I have successfully connected my application to the CasparCG server and they are talking... I can send basic commands to the server and play my flash template...

My problem is that I need to send xml data to the CasparCG server over the socket... and put into the XML a value from my scoreboard (a LiveCode field... say T1Score for Team 1's Score)

The command I need to send to the Caspar Server is where $$T1Score$$ is the value from my LiveCode field T1Score:

CG 1 UPDATE 1 "<templateData><componentData id=\"t1\"><data id=\"text\" value=\"$$T1Score$$\" /></componentData></templateData>"

My first question is how can I pull the value from T1Score to use in my XML to the server.

My second question is how to send the XML to the server correctly.... I placed the following code as a test into the T1Score field to see if I can send it to the server.

on textchanged
write "CG 1 UPDATE 1 "<templateData><componentData id=\"t1\"><data id=\"text\" value=\"T1Score\" /></componentData></templateData>" & format("\r\n") to socket "localhost:5250"
end textchanged

The code turns red after

write "CG 1 UPDATE 1 "<templateData><componentData id=\

And I get the error:

field "T1Score": compilation error at line 2 (Expression: bad factor) near "><", char 30

Usefull links:
I don't have permission to post URL's but the info is on CasparCG's wiki if you google "CasparCG_2.0_AMCP_Protocol Template_Data" you will find it.

aircooled76
Posts: 38
Joined: Mon May 20, 2013 3:14 pm

Re: Sending XML data over a Socket Connection - CasparCG

Post by aircooled76 » Mon May 20, 2013 6:13 pm

OK... some heavy googling and I found a solution!!! (well not a very elegent one but hey...)

The quotes were the problem... LiveCode treats them as a Literal...

Basically i create a variable (in this case s1xml) and add the sections of the code between the quotes I need to the variable... then put the whole variable in one hit to the socket. COOL... got me a working scoreboard... although I am open to a better and more graceful way of doing this...

put "CG 1 UPDATE 1 " into s1xml
put quote after s1xml
put "<templateData><componentData id=\" after s1xml
put quote after s1xml
put "s1\" after s1xml
put quote after s1xml
put "><data id=\" after s1xml
put quote after s1xml
put "text\" after s1xml
put quote after s1xml
put " value=\" after s1xml
put quote after s1xml
put field t1score after s1xml
put "\" after s1xml
put quote after s1xml
put " /></componentData></templateData>" after s1xml
put quote after s1xml
put quote in server
put field IP after server
put quote after server
write s1xml & format("\r\n") to socket server

The answer to my first question is a bit embarrassing you just put in "put field t1score after s1xml" to pull the field value... Well I am not doing too bad in my third day of LiveCode :)


Great info here... it is a shame we can't post the usefull URL's we find :(
(good info at site: revolution byu edu / transcript / Transcript1 . php)

aircooled76
Posts: 38
Joined: Mon May 20, 2013 3:14 pm

Re: Sending XML data over a Socket Connection - CasparCG

Post by aircooled76 » Sun Jun 02, 2013 2:08 pm

OK... I have found a better way by using & quote & to insert the quotations I need...

Code: Select all

 write "CG 1-2 UPDATE 1 "& quote &"<templateData><componentData id=\"& quote &"f1\"& quote &"><data id=\"& quote &"text\"& quote &" value=\" & quote & field GameClock "\"& quote &" /></componentData></templateData>" & format("\r\n") to socket field IP
but I get a compiling error

Code: Select all

button "Test UpdateClock": compilation error at line 2 (write: missing 'to'), char 157 
at the point I am trying to insert the field "GameClock" into the string... any suggestions on what I am doing wrong?

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Sending XML data over a Socket Connection - CasparCG

Post by sturgis » Sun Jun 02, 2013 2:16 pm

Looks like you're missing an ampersand.

field GameClock & "\"

Also you should quote Gameclock

field "Gameclock" & "\" & quote..

Post Reply