I just started playing w/ JSON and I've found information to be scattered and vague so I'm going to put what I've discovered so far here in case someone else is going to give this a try. The language I'm using (AMX's Neltinx) doesn't have all the various functions and handlers that other languages do which is why most of the references and examples I've found to be pretty much useless.
In my code I open a TCP socket to the IP of my LMS on port 9000.
When the connection is established I'm issued and "ONLINE" event to let me know the connection has been established and I use that to trigger sending my queued commands to LMS.
Here's some valid commands string that I used for testing:
Prior to sending the string I populate my variable to hold a string:
The single quotes indicates a string literal.
Wireshark intercepts between PC and LMS running on a remote vortexbox showed the exchange coming from the PC to control LMS and I modified it into the format I need to send these strings from an AMX controller.
Again single quotes indicate a string literal and the double quotes outside concatenate different variables and data types into a single string for sending. STR_CRLF is just a constant for carriage return, line feed (Hex $0d,$0a or decimal 13,10).
After playing around a little I found the server will function just fine if only sent, maybe less but it's reduced enough for me:
I haven't played around to see if the connection can be maintained or if I need to open the socket and close it for every command which would be typical for http.
In my code I open a TCP socket to the IP of my LMS on port 9000.
When the connection is established I'm issued and "ONLINE" event to let me know the connection has been established and I use that to trigger sending my queued commands to LMS.
Here's some valid commands string that I used for testing:
Code:
{"id":1,"method":"slim.request","params":["00:04:20:1a:ea:f6",["status","-",1,"tags:al"]]} {"id":1,"method":"slim.request","params":[ "", ["albums", "0","50" ]]} {"id":1,"method":"slim.request","params":["00:04:20:1a:ea:f6",["play"]]} {"id":1,"method":"slim.request","params":["00:04:20:1a:ea:f6",["status","-",1,"tags:uB"]]} {"id":1,"method":"slim.request","params":["",["serverstatus",0,999]]}
Code:
sJSON.sPlayer.cCmd = '{"id":1,"method":"slim.request","params":["00:04:20:1a:ea:f6",["status","-",1,"tags:uB"]]}';
Wireshark intercepts between PC and LMS running on a remote vortexbox showed the exchange coming from the PC to control LMS and I modified it into the format I need to send these strings from an AMX controller.
Code:
SEND_STRING dvJSON,"'POST /jsonrpc.js HTTP/1.1',STR_CRLF"; SEND_STRING dvJSON,"'Host: ',sJSON.sPlayer.cIP,':',itoa(sJSON.sPlayer.nPort),STR_CRLF"; SEND_STRING dvJSON,"'User-Agent: User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0',STR_CRLF"; SEND_STRING dvJSON,"'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',STR_CRLF"; SEND_STRING dvJSON,"'Accept-Language: en-us',STR_CRLF"; SEND_STRING dvJSON,"'Accept-Encoding: gzip, deflate',STR_CRLF"; SEND_STRING dvJSON,"'X-Requested-With: XMLHttpRequest',STR_CRLF"; SEND_STRING dvJSON,"'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',STR_CRLF"; SEND_STRING dvJSON,"'Referer: http://',sJSON.sPlayer.cIP,':',itoa(sJSON.sPlayer.nPort),'/',STR_CRLF"; SEND_STRING dvJSON,"'Content-Length: ',itoa(length_string(sJSON.sPlayer.cCmd)),STR_CRLF"; SEND_STRING dvJSON,"'Cookie: Squeezebox-player=',fnEncodeURL(sJSON.sPlayer.cStrMAC),'; Squeezebox-expandPlayerControl=false; ', 'Squeezebox-expanded-MY_MUSIC=1; Squeezebox-expanded-RADIO=0; Squeezebox-expanded-PLUGIN_MY_APPS_MODULE_NAME=1; ', 'Squeezebox-expanded-FAVORITES=0; Squeezebox-expanded-PLUGINS=0; Squeezebox-playersettings=null; ', 'Squeezebox-advancedsettings=settings/server/debugging.html%3F; Squeezebox-expanded-updatePlugins=1; ', 'Squeezebox-expanded-activePlugins=1; Squeezebox-expanded-inactivePlugins=1; Squeezebox-expanded-otherPlugins0=1; ', 'Squeezebox-expanded-otherPlugins1=1; __utma=124789194.27251913.1391382619.1391382619.1391382619.1; ', '__utmz=124789194.1391382619.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)',STR_CRLF"; SEND_STRING dvJSON,"'Connection: keep-alive',STR_CRLF"; SEND_STRING dvJSON,"'Pragma: no-cache',STR_CRLF"; SEND_STRING dvJSON,"'Cache-Control: no-cache',STR_CRLF"; SEND_STRING dvJSON,"STR_CRLF"; SEND_STRING dvJSON,"sJSON.sPlayer.cCmd,STR_CRLF";
After playing around a little I found the server will function just fine if only sent, maybe less but it's reduced enough for me:
Code:
SEND_STRING dvJSON,"'POST /jsonrpc.js HTTP/1.1',STR_CRLF"; SEND_STRING dvJSON,"'Host: ',sJSON.sPlayer.cIP,':',itoa(sJSON.sPlayer.nPort),STR_CRLF"; SEND_STRING dvJSON,"'Referer: http://',sJSON.sPlayer.cIP,':',itoa(sJSON.sPlayer.nPort),'/',STR_CRLF"; SEND_STRING dvJSON,"'Content-Length: ',itoa(length_string(sJSON.sPlayer.cCmd)),STR_CRLF"; SEND_STRING dvJSON,"STR_CRLF"; SEND_STRING dvJSON,"sJSON.sPlayer.cCmd,STR_CRLF";
Comment