Source language: Translate to:

TCP Websocket String..

General questions about NeoAppBuilder - our rapid application development tool for building HTML5, web and mobile apps.

Moderator: Neosoft Support

TCP Websocket String..

Postby TinTin » Wed Apr 06, 2016 4:13 am

Hi all..

I'm trying to parse an incoming socket string from Javascript - it has some ASCII characters one being #CAN
I know it's possible to parse ',' in NAB, as in NB one would simply insert the ACSII value like [#24] but this doesn't seem
to be playing fair in NAB..

Any help would be appreciated.
TinTin
 
Posts: 162
Joined: Sun Dec 06, 2009 4:03 am
Location: UK

Re: TCP Websocket String..

Postby Gaev » Wed Apr 06, 2016 5:07 am

TinTin:

Please post example values of input string and expected result ... and the command(s) you are attempting to accomplish this.
User avatar
Gaev
 
Posts: 3717
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: TCP Websocket String..

Postby TinTin » Wed Apr 06, 2016 5:41 am

Hi Gaev,

Examples as follows:

Am using JS Websocket Client to grab the string

function onMessage(ws){
$rootScope.gridmsg = ws.data;
}



The Websocket string is sent from my server app..


#DC2Start,12:08:26,99#CANReset, No Action,12:08:27/Start,12:08:28,01,Server,005,00,00,Apple,1#DC2Start,12:08:28,99#CANReset, No Action,12:08:29/Start,12:09:07,01,Server,001,04,00,Pear

(#DC2 and #CAN are ascii within the string)


However I think NAB maybe just reading the last part of the websocket string / I've even tried "/r/n" because I think NAB is only showing last part of the websocket string.
Even if I could parse the '/' character it would possibly help.

So if I try and do ie:

StrParse "[gridmsg]" "#CAN" [newmessage]


It doesn't seems to create an array..
I can pass the ',' comma into array no problem.. but that is just the last part of the string which is parsed.


It's quite possible I'm doing something quite wrong.. :-(
TinTin
 
Posts: 162
Joined: Sun Dec 06, 2009 4:03 am
Location: UK

Re: TCP Websocket String..

Postby Gaev » Wed Apr 06, 2016 6:16 am

TinTin:

According to the ASCII Table here ... http://www.asciitable.com/ ...

ascii code DC2 has a value of decimal 18 (or hexadecimal 12)
ascii code CAN has a value of decimal 24 (or hexadecimal 18)

I don't know if NAB supports the NeoBook representations for character codes ... so you can first try ...
Code: Select all
StrParse "[gridmsg]" "[#24]" [newmessage]


If that does not work, you might try and replace the byte values for these special codes (to something that is not normally found in the rest of the string) in your javascript function before sending ws.data to gridmsg ...
Code: Select all
function onMessage(ws){
var receivedData = ws.data;
var codeCAN = String.fromCharCode(24);
var replacedData = receivedData.replace(codeCAN, "TinTinTinCAN");
$rootScope.gridmsg = replacedData;
}

... and then parse the gridmsg variable on "TinTinTinCAN")
User avatar
Gaev
 
Posts: 3717
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: TCP Websocket String..

Postby TinTin » Wed Apr 06, 2016 11:09 am

Hi Gaev,

Thanks for your help, much appreciated - your method is correct I have tested, however I've now looked into the incoming socket connection and found the issue, the websocket data is being sent as separate messages not as one string (as I originally thought), in JS can you create array into NAB from each socket string , I would imagine now there is /r/n end of line termination for each message?
TinTin
 
Posts: 162
Joined: Sun Dec 06, 2009 4:03 am
Location: UK

Re: TCP Websocket String..

Postby TinTin » Wed Apr 06, 2016 12:14 pm

Gaev,

Figured it, it was actually in your ws example which logged the message strings within the JS - I just have to parse and clean up each time as message is received..! Thanks for your help.
TinTin
 
Posts: 162
Joined: Sun Dec 06, 2009 4:03 am
Location: UK

Re: TCP Websocket String..

Postby Gaev » Wed Apr 06, 2016 12:18 pm

TinTin:

the websocket data is being sent as separate messages not as one string (as I originally thought),

It is always best if you describe it in technical terms ... I have no idea what you mean by "separate messages" ...

a) how did you determine that this string was being received in the first place ? ...

#DC2Start,12:08:26,99#CANReset, No Action,12:08:27/Start,12:08:28,01,Server,005,00,00,Apple,1#DC2Start,12:08:28,99#CANReset, No Action,12:08:29/Start,12:09:07,01,Server,001,04,00,Pear

... or did you assume that what was sent was going to be what was received ?

b) when trouble shooting, best to check things (to confirm assumptions) one step at a time ... so best to do javascript alert commands on ws.data (size/length and content) ... and if necessary, examine/alert each byte

c) post here, details of the content of "each message"

in JS can you create array into NAB from each socket string, I would imagine now there is /r/n end of line termination for each message?

a) best to confirm what is being received ... then coming up with a solution to any perceived road blocks

b) I don't know about javascript arrays to NAB variable space ... but easiest if you combine the arrays on the javascript side (use a unique separator string like TinTinTinArrayItem) ... pass the combined string as text ... and then parse it back on the other side.
User avatar
Gaev
 
Posts: 3717
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: TCP Websocket String..

Postby TinTin » Wed Apr 06, 2016 12:31 pm

Hi Gaev,

I had used a raw socket windows application to grab the data, that's how I was able to be assured the string format, do you know if there is going to be an integrated debug viewer for NAB, that would be useful, I know there's the developer console in Chrome...

Cheers
TinTin
 
Posts: 162
Joined: Sun Dec 06, 2009 4:03 am
Location: UK

Re: TCP Websocket String..

Postby Gaev » Wed Apr 06, 2016 1:16 pm

TinTin:

I had used a raw socket windows application to grab the data, that's how I was able to be assured the string format

Are you able to share details of this process (either publicly or via Private Message) ? ... so I can try and replicate it and find out the exact data returned.

do you know if there is going to be an integrated debug viewer for NAB, that would be useful, I know there's the developer console in Chrome...

I do not have any inside track on NAB feature upgrades ... does the Chrome Developer Console not give you what you need ?
User avatar
Gaev
 
Posts: 3717
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: TCP Websocket String..

Postby TinTin » Thu Apr 07, 2016 1:37 am

Hi Gaev,

I think you may have missed a post along the way ;-)


Gaev,

Figured it, it was actually in your ws example which logged the message strings within the JS - I just have to parse and clean up each time as message is received..! Thanks for your help.

function wsLogMessage(logText){
wsLog = wsLog + "\n" + logText;
}
TinTin
 
Posts: 162
Joined: Sun Dec 06, 2009 4:03 am
Location: UK

Re: TCP Websocket String..

Postby Gaev » Thu Apr 07, 2016 4:33 am

TinTin:

I think you may have missed a post along the way


From the time stamps of the posts, it looks like you posted while I was composing mine ... sorry about the confusion.
User avatar
Gaev
 
Posts: 3717
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: TCP Websocket String..

Postby TinTin » Sat Apr 09, 2016 2:45 am

No problem, thanks for your help.
TinTin
 
Posts: 162
Joined: Sun Dec 06, 2009 4:03 am
Location: UK


Return to General NeoAppBuilder Discussion

Who is online

Users browsing this forum: No registered users and 0 guests