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:
>> I don't understand what is causing the error. Can you please suggest what I 
>> am doing wrong?
>> 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)
>> 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
> 

Reply via email to