Hi, I need to send a JSON object to the JSON messenger from a .js file. Can you suggest the method to do that? I am using nodejs. I tried the net.Socket() function in nodejs but it wasn't able to communicate.
Even when I tried in python according to the thread ( https://groups.google.com/forum/#!searchin/nox_dev/json$20messenger$20example/nox_dev/nbHEFiYAFrk/OOcz7EF2BJUJ), I got the following error: 00002|nox|INFO:nox bootstrap complete {u'type': u'connect'} 00003|pyrt|ERR:Python handler returned invalid Disposition. 00004|nox.loadbalancer.lbtest.lbtest|INFO:{u'type': u'connect'} {u'type': u'disconnect'} 00005|pyrt|ERR:Python handler returned invalid Disposition. 00006|nox.loadbalancer.lbtest.lbtest|INFO:{u'type': u'disconnect'} with the following handler: def myHandler (self, e): import json Globals.log.info(json.loads(e.jsonstring)) e.reply(json.dumps({"msg":"Hello world"})) return CONTINUE Regards, Neha On Wed, Aug 8, 2012 at 11:16 PM, Murphy McCauley <[email protected]>wrote: > Cut and pasted from a thread which has been mentioned a couple of times > now (https://groups.google.com/d/msg/nox_dev/K3rB8a_dKaI/XKOU4Mo1dYQJ): > > > Messages for messenger are prefixed with a three byte header: > > 2 Byte Network Order Unsigned Integer: > > Message length (including header) > > 1 Byte: > > Message type (can be anything, but I think 0-9 are reserved -- see > messenger.hh) > > > Then, if you look at messenger.hh as suggested in that message (you can > look in the code or the doxygen which has also been linked to in this > thread), you'll find the msg_type enumeration, which is further expanded on > here: > > http://www.noxrepo.org/_/nox-classic-doxygen/namespacevigil.html#a15dd704d3b814b7c016a317834b77bef > > Cut and pasting it here... > Type value 0x00 to 0x09 are reserved for internal use. > > MSG_DISCONNECT Disconnection message. Need to be consistent. > MSG_ECHO Echo message. Need to be consistent. > MSG_ECHO_RESPONSE Response message. Need to be consistent. > MSG_AUTH Authentication. Need to be consistent. > MSG_AUTH_RESPONSE Authenication response. Need to be consistent. > MSG_AUTH_STATUS Authentication status. Need to be consistent. > MSG_NOX_STR_CMD Plain string. > > > So, in short, you need to send two bytes of length, 1 byte of type (which > should be something > 9), and THEN your data. I think the following will > do it: > > String s = "Neha"; > dos.writeShort(3 + s.length()); > dos.writeByte(42); // Arbitrary 'type' value > dos.writeBytes(s); > > > -- Murphy > > On Aug 8, 2012, at 7:22 AM, Neha Jatav wrote: > > Thanks Kyriakos & Murphy! All of that worked except that the .body > attribute returned an empty string. I printed e.type and it was 0. I am > using a simple JAVA application t send message as follows:- > > Socket newsock = new Socket("localhost", 2603); > System.out.println("Connected to localhost in port 2603"); > DataOutputStream dos = new > DataOutputStream(newsock.getOutputStream()); > > dos.write("Neha".getBytes()); > > dos.close(); > newsock.close(); > > Can you please tell me what might possibly wrong in my approach. > > Regards, > Neha > > On Wed, Aug 8, 2012 at 2:15 AM, Murphy McCauley <[email protected] > > wrote: > >> On Aug 7, 2012, at 4:26 AM, Neha Jatav wrote: >> >> >> 1. I don't understand what is causing the error. Can you please >> suggest what I am doing wrong? >> 2. I want to obtain the message in the form of a string. What is the >> function to convert the incoming message into a string? (something >> analogous to e.jsonstring in the JSON messenger handler) >> 3. I would like to add this messenger to my existing NOX application. >> Do I just add the "def configure" alongside "def install" & "def >> getInterface"? Do I need to append anything to the "def __init__"? >> >> Here's the link again to one of the threads I posted earlier: >> https://groups.google.com/d/msg/nox_dev/K3rB8a_dKaI/XKOU4Mo1dYQJ >> >> It has an example of using the messenger. >> >> Addressing your points specifically: >> 1) Kyriakos got this one >> 2) This is shown in step 2 of the above link. It's the event's .body >> attribute. >> 3) It looks like you're currently modifying messenger.py. Don't. The >> proper procedure is shown in steps 1 and 3 of the above link. Create your >> own component. import Msg_event and register a handler in your install >> function. Add pymessenger as a dependency in the meta.json. >> >> -- Murphy >> > > >
