[nox-dev] Receiving JSON messages

2012-01-24 Thread Giorgio Mazza

Hi all!
I have written a simple component in python that works fine.
Now I would to improve it, making it to install flow entries depending 
on parameters received from an external application.
In particular I want to pass those parameters via json messages to my 
component, which, in my thougths, has to open a "permanent" socket 
listening for them, save those parameters in a dictionary and, as a 
consequence, decide the desired switch behaviour (whether install or not 
a flow entry for the received parameters).
In previous threads I found that I have to use jsonmessenger (even in 
python?) or to have a look to discovery.py, but I am not sure to have 
understood what I have to do and where in order to realize such a behaviour.

Could anyone, please, help me?
Thank you in advance,

Giorgio Mazza
___
nox-dev mailing list
nox-dev@noxrepo.org
http://noxrepo.org/mailman/listinfo/nox-dev


Re: [nox-dev] Receiving JSON messages

2012-01-24 Thread Giorgio Mazza

Thank you.
I try to sum up the operations I need to perform, to see if I understood 
correctly.
Basically in my external application I have to set up a socket that 
sends json messages and this would be quite simple.
In my nox component, instead, I have to import the "JSONMsg_event" and, 
within the "install()" instruction, to handle it with my specific 
method, that, in my case, would only save these json messages into a 
dictionary, for using them later, according to some conditions.

Is that correct?

A couple of things that I didn't understand:
- I assume I also have to set up a server socket in my nox component, in 
order to receive json messages and handle  JSONMsg_events. So, I think 
this socket has to be already up and running when I handle the event. 
So, when do I have to create it and how? Do I have to use messenger.py 
channel class?
- Second question, probably related to the first. I think to be pretty 
confused about jsonmessenger: what are the jsonmessenger files I could 
look into in order to understand fields and methods that I would need to 
use? Are the jsonmessenger.cc and jsonmessenger.hh in 
nox/src/nox/coreapps/messenger? And, if it is the case, how can I 
integrate them into a python component?


Thanks again,

Giorgio

On 24/01/2012 12:28, Kyriakos Zarifis wrote:

Hi Giorgio,

yes, I think using jsonmessenger would be the best approach for this.

you need to implement a send/receive interface on the external 
application and in your nox component. For the external application, 
it's pretty straightforward - Connect to the jsonmessenger socket and 
send json strings. In your nox application you need to register for 
JSON messages, and handle them appropriately.


The wiki explains the communication in a few steps (specifically for 
the GUI<->NOX, but it will be similar and simpler for any external 
app) here 
:


If you want to see a full example, the GUI 
 and the monitoring 
 component in destiny could be a place to 
look. I'm afraid it's much more complex than what you need, but the 
bits you need are in there if you dig in the code a bit.



On Tue, Jan 24, 2012 at 2:16 AM, Giorgio Mazza 
mailto:giorgio.mazza...@gmail.com>> wrote:


Hi all!
I have written a simple component in python that works fine.
Now I would to improve it, making it to install flow entries
depending on parameters received from an external application.
In particular I want to pass those parameters via json messages to
my component, which, in my thougths, has to open a "permanent"
socket listening for them, save those parameters in a dictionary
and, as a consequence, decide the desired switch behaviour
(whether install or not a flow entry for the received parameters).
In previous threads I found that I have to use jsonmessenger (even
in python?) or to have a look to discovery.py, but I am not sure
to have understood what I have to do and where in order to realize
such a behaviour.
Could anyone, please, help me?
Thank you in advance,

Giorgio Mazza
___
nox-dev mailing list
nox-dev@noxrepo.org 
http://noxrepo.org/mailman/listinfo/nox-dev




___
nox-dev mailing list
nox-dev@noxrepo.org
http://noxrepo.org/mailman/listinfo/nox-dev


Re: [nox-dev] Receiving JSON messages

2012-01-24 Thread Murphy McCauley
The minimum to get up and going should be something like this:

1) In your component's install function:
from nox.coreapps.messenger.pymsgevent import JSONMsg_event
JSONMsg_event.register_event_converter(self.ctxt)
self.register_handler(JSONMsg_event.static_get_name(), myHandler)

2) Implement a handler:
def myHandler (e):
  import json
  print json.loads(e.jsonstring)
  e.reply(json.dumps({"msg":"Hello world"}))

3) Include jsonmessenger on the commandline or as a dependency


That may not be exactly correct -- it's adapted from a quick writeup I did in 
December about using the new Python support for the "regular" messenger (as 
opposed to the JSON messenger), which has not yet been pushed to the 
repository.  For reference, that post was:
http://noxrepo.org/pipermail/nox-dev/2011-December/008382.html

(If using the new version of messenger that I linked to in that post, you 
remove the register_event_converter() call from step 1 and include 
pyjsonmessenger instead of jsonmessenger in step 3.)

Invoking the jsonmessenger component (on the commandline or by including it as 
a dependency in your app's meta.json) will create the server socket for you.

You absolutely do not have to use the messenger.py class.  I'm removing it from 
that directory, because all it ever does is confuse people -- it really doesn't 
belong there.  messenger.py is a library for writing JSON messenger *clients* 
(external programs) in Python.  That may be useful to you, but you don't need 
it for the NOX side of things.

Hope that helps.

-- Murphy

On Jan 24, 2012, at 4:12 AM, Giorgio Mazza wrote:

> Thank you.
> I try to sum up the operations I need to perform, to see if I understood 
> correctly.
> Basically in my external application I have to set up a socket that sends 
> json messages and this would be quite simple.
> In my nox component, instead, I have to import the "JSONMsg_event" and, 
> within the "install()" instruction, to handle it with my specific method, 
> that, in my case, would only save these json messages into a dictionary, for 
> using them later, according to some conditions.
> Is that correct?
> 
> A couple of things that I didn't understand:
> - I assume I also have to set up a server socket in my nox component, in 
> order to receive json messages and handle  JSONMsg_events. So, I think this 
> socket has to be already up and running when I handle the event. So, when do 
> I have to create it and how? Do I have to use messenger.py channel class?
> - Second question, probably related to the first. I think to be pretty 
> confused about jsonmessenger: what are the jsonmessenger files I could look 
> into in order to understand fields and methods that I would need to use? Are 
> the jsonmessenger.cc and jsonmessenger.hh in nox/src/nox/coreapps/messenger? 
> And, if it is the case, how can I integrate them into a python component?
> 
> Thanks again,
> 
> Giorgio
> 
> On 24/01/2012 12:28, Kyriakos Zarifis wrote:
>> 
>> Hi Giorgio,
>> 
>> yes, I think using jsonmessenger would be the best approach for this.
>> 
>> you need to implement a send/receive interface on the external application 
>> and in your nox component. For the external application, it's pretty 
>> straightforward - Connect to the jsonmessenger socket and send json strings. 
>> In your nox application you need to register for JSON messages, and handle 
>> them appropriately. 
>> 
>> The wiki explains the communication in a few steps (specifically for the 
>> GUI<->NOX, but it will be similar and simpler for any external app) here:
>> 
>> If you want to see a full example, the GUI and the monitoring component in 
>> destiny could be a place to look. I'm afraid it's much more complex than 
>> what you need, but the bits you need are in there if you dig in the code a 
>> bit.
>> 
>> 
>> On Tue, Jan 24, 2012 at 2:16 AM, Giorgio Mazza  
>> wrote:
>> Hi all!
>> I have written a simple component in python that works fine.
>> Now I would to improve it, making it to install flow entries depending on 
>> parameters received from an external application.
>> In particular I want to pass those parameters via json messages to my 
>> component, which, in my thougths, has to open a "permanent" socket listening 
>> for them, save those parameters in a dictionary and, as a consequence, 
>> decide the desired switch behaviour (whether install or not a flow entry for 
>> the received parameters).
>> In previous threads I found that I have to use jsonmessenger (even in 
>> python?) or to have a look to discovery.py, but I am not sure to have 
>> understood what I have to do and where in order to realize such a behaviour.
>> Could anyone, please, help me?
>> Thank you in advance,
>> 
>> Giorgio Mazza
>> ___
>> nox-dev mailing list
>> nox-dev@noxrepo.org
>> http://noxrepo.org/mailman/listinfo/nox-dev
>> 
> 
> ___
> nox-dev mailing list
> nox-dev@noxrepo.org
> http://noxrepo.org/mai

Re: [nox-dev] Receiving JSON messages

2012-01-24 Thread Giorgio Mazza

Ok, thanks.
Now things are more clear in my mind.
I'll try and let you know if I succeed. Otherwise I would bother you 
again :)

Regards,

Giorgio

On 24/01/2012 13:49, Murphy McCauley wrote:

The minimum to get up and going should be something like this:

1) In your component's install function:
from nox.coreapps.messenger.pymsgevent import JSONMsg_event
JSONMsg_event.register_event_converter(self.ctxt)
self.register_handler(JSONMsg_event.static_get_name(), myHandler)

2) Implement a handler:
def myHandler (e):
  import json
  print json.loads(e.jsonstring)
  e.reply(json.dumps({"msg":"Hello world"}))

3) Include jsonmessenger on the commandline or as a dependency


That may not be exactly correct -- it's adapted from a quick writeup I 
did in December about using the new Python support for the "regular" 
messenger (as opposed to the JSON messenger), which has not yet been 
pushed to the repository.  For reference, that post was:

http://noxrepo.org/pipermail/nox-dev/2011-December/008382.html

(If using the new version of messenger that I linked to in that post, 
you remove the register_event_converter() call from step 1 and include 
pyjsonmessenger instead of jsonmessenger in step 3.)


Invoking the jsonmessenger component (on the commandline or by 
including it as a dependency in your app's meta.json) will create the 
server socket for you.


You absolutely do not have to use the messenger.py class.  I'm 
removing it from that directory, because all it ever does is confuse 
people -- it really doesn't belong there.  messenger.py is a library 
for writing JSON messenger *clients* (external programs) in Python. 
 That may be useful to you, but you don't need it for the NOX side of 
things.


Hope that helps.

-- Murphy

On Jan 24, 2012, at 4:12 AM, Giorgio Mazza wrote:


Thank you.
I try to sum up the operations I need to perform, to see if I 
understood correctly.
Basically in my external application I have to set up a socket that 
sends json messages and this would be quite simple.
In my nox component, instead, I have to import the "JSONMsg_event" 
and, within the "install()" instruction, to handle it with my 
specific method, that, in my case, would only save these json 
messages into a dictionary, for using them later, according to some 
conditions.

Is that correct?

A couple of things that I didn't understand:
- I assume I also have to set up a server socket in my nox component, 
in order to receive json messages and handle  JSONMsg_events. So, I 
think this socket has to be already up and running when I handle the 
event. So, when do I have to create it and how? Do I have to use 
messenger.py channel class?
- Second question, probably related to the first. I think to be 
pretty confused about jsonmessenger: what are the jsonmessenger files 
I could look into in order to understand fields and methods that I 
would need to use? Are the jsonmessenger.cc and jsonmessenger.hh in 
nox/src/nox/coreapps/messenger? And, if it is the case, how can I 
integrate them into a python component?


Thanks again,

Giorgio

On 24/01/2012 12:28, Kyriakos Zarifis wrote:

Hi Giorgio,

yes, I think using jsonmessenger would be the best approach for this.

you need to implement a send/receive interface on the external 
application and in your nox component. For the external application, 
it's pretty straightforward - Connect to the jsonmessenger socket 
and send json strings. In your nox application you need to register 
for JSON messages, and handle them appropriately.


The wiki explains the communication in a few steps (specifically for 
the GUI<->NOX, but it will be similar and simpler for any external 
app) here 
:


If you want to see a full example, the GUI 
 and the monitoring 
 component in destiny could be a place 
to look. I'm afraid it's much more complex than what you need, but 
the bits you need are in there if you dig in the code a bit.



On Tue, Jan 24, 2012 at 2:16 AM, Giorgio Mazza 
mailto:giorgio.mazza...@gmail.com>> wrote:


Hi all!
I have written a simple component in python that works fine.
Now I would to improve it, making it to install flow entries
depending on parameters received from an external application.
In particular I want to pass those parameters via json messages
to my component, which, in my thougths, has to open a
"permanent" socket listening for them, save those parameters in
a dictionary and, as a consequence, decide the desired switch
behaviour (whether install or not a flow entry for the received
parameters).
In previous threads I found that I have to use jsonmessenger
(even in python?) or to have a look to discovery.py, but I am
not sure to have understood what I have to do and where in order
to realize such a behaviour.
Could anyone, please, help me?
Thank you in advance,

  

Re: [nox-dev] Receiving JSON messages

2012-01-25 Thread Giorgio Mazza

A question about the socket opened when invoking jsonmessenger.
What are the IP address, the tcp port and the interface that this socket 
refers to? Is there any way to set them?
I undersotood the mechanism, but I don't know where to send my messages 
from the external application.

Thank you.
Regards,

Giorgio

On 24/01/2012 13:49, Murphy McCauley wrote:

The minimum to get up and going should be something like this:

1) In your component's install function:
from nox.coreapps.messenger.pymsgevent import JSONMsg_event
JSONMsg_event.register_event_converter(self.ctxt)
self.register_handler(JSONMsg_event.static_get_name(), myHandler)

2) Implement a handler:
def myHandler (e):
  import json
  print json.loads(e.jsonstring)
  e.reply(json.dumps({"msg":"Hello world"}))

3) Include jsonmessenger on the commandline or as a dependency


That may not be exactly correct -- it's adapted from a quick writeup I 
did in December about using the new Python support for the "regular" 
messenger (as opposed to the JSON messenger), which has not yet been 
pushed to the repository.  For reference, that post was:

http://noxrepo.org/pipermail/nox-dev/2011-December/008382.html

(If using the new version of messenger that I linked to in that post, 
you remove the register_event_converter() call from step 1 and include 
pyjsonmessenger instead of jsonmessenger in step 3.)


Invoking the jsonmessenger component (on the commandline or by 
including it as a dependency in your app's meta.json) will create the 
server socket for you.


You absolutely do not have to use the messenger.py class.  I'm 
removing it from that directory, because all it ever does is confuse 
people -- it really doesn't belong there.  messenger.py is a library 
for writing JSON messenger *clients* (external programs) in Python. 
 That may be useful to you, but you don't need it for the NOX side of 
things.


Hope that helps.

-- Murphy

On Jan 24, 2012, at 4:12 AM, Giorgio Mazza wrote:


Thank you.
I try to sum up the operations I need to perform, to see if I 
understood correctly.
Basically in my external application I have to set up a socket that 
sends json messages and this would be quite simple.
In my nox component, instead, I have to import the "JSONMsg_event" 
and, within the "install()" instruction, to handle it with my 
specific method, that, in my case, would only save these json 
messages into a dictionary, for using them later, according to some 
conditions.

Is that correct?

A couple of things that I didn't understand:
- I assume I also have to set up a server socket in my nox component, 
in order to receive json messages and handle  JSONMsg_events. So, I 
think this socket has to be already up and running when I handle the 
event. So, when do I have to create it and how? Do I have to use 
messenger.py channel class?
- Second question, probably related to the first. I think to be 
pretty confused about jsonmessenger: what are the jsonmessenger files 
I could look into in order to understand fields and methods that I 
would need to use? Are the jsonmessenger.cc and jsonmessenger.hh in 
nox/src/nox/coreapps/messenger? And, if it is the case, how can I 
integrate them into a python component?


Thanks again,

Giorgio

On 24/01/2012 12:28, Kyriakos Zarifis wrote:

Hi Giorgio,

yes, I think using jsonmessenger would be the best approach for this.

you need to implement a send/receive interface on the external 
application and in your nox component. For the external application, 
it's pretty straightforward - Connect to the jsonmessenger socket 
and send json strings. In your nox application you need to register 
for JSON messages, and handle them appropriately.


The wiki explains the communication in a few steps (specifically for 
the GUI<->NOX, but it will be similar and simpler for any external 
app) here 
:


If you want to see a full example, the GUI 
 and the monitoring 
 component in destiny could be a place 
to look. I'm afraid it's much more complex than what you need, but 
the bits you need are in there if you dig in the code a bit.



On Tue, Jan 24, 2012 at 2:16 AM, Giorgio Mazza 
mailto:giorgio.mazza...@gmail.com>> wrote:


Hi all!
I have written a simple component in python that works fine.
Now I would to improve it, making it to install flow entries
depending on parameters received from an external application.
In particular I want to pass those parameters via json messages
to my component, which, in my thougths, has to open a
"permanent" socket listening for them, save those parameters in
a dictionary and, as a consequence, decide the desired switch
behaviour (whether install or not a flow entry for the received
parameters).
In previous threads I found that I have to use jsonmessenger
(even in python?) or to have a look to discovery.py, but I am
 

Re: [nox-dev] Receiving JSON messages

2012-01-25 Thread Murphy McCauley
I believe it defaults to port 2703.  You should be able to set the port number 
by specifying it on the commandline...
./nox_core -i ptcp: jsonmessenger=tcpport=4096 your_app_here

It listens on all IP addresses; there is currently no way to specify just one.

-- Murphy

On Jan 25, 2012, at 1:11 PM, Giorgio Mazza wrote:

> A question about the socket opened when invoking jsonmessenger.
> What are the IP address, the tcp port and the interface that this socket 
> refers to? Is there any way to set them?
> I undersotood the mechanism, but I don't know where to send my messages from 
> the external application.
> Thank you.
> Regards,
> 
> Giorgio
> 
> On 24/01/2012 13:49, Murphy McCauley wrote:
>> 
>> The minimum to get up and going should be something like this:
>> 
>> 1) In your component's install function:
>> from nox.coreapps.messenger.pymsgevent import JSONMsg_event
>> JSONMsg_event.register_event_converter(self.ctxt)
>> self.register_handler(JSONMsg_event.static_get_name(), myHandler)
>> 
>> 2) Implement a handler:
>> def myHandler (e):
>>   import json
>>   print json.loads(e.jsonstring)
>>   e.reply(json.dumps({"msg":"Hello world"}))
>> 
>> 3) Include jsonmessenger on the commandline or as a dependency
>> 
>> 
>> That may not be exactly correct -- it's adapted from a quick writeup I did 
>> in December about using the new Python support for the "regular" messenger 
>> (as opposed to the JSON messenger), which has not yet been pushed to the 
>> repository.  For reference, that post was:
>> http://noxrepo.org/pipermail/nox-dev/2011-December/008382.html
>> 
>> (If using the new version of messenger that I linked to in that post, you 
>> remove the register_event_converter() call from step 1 and include 
>> pyjsonmessenger instead of jsonmessenger in step 3.)
>> 
>> Invoking the jsonmessenger component (on the commandline or by including it 
>> as a dependency in your app's meta.json) will create the server socket for 
>> you.
>> 
>> You absolutely do not have to use the messenger.py class.  I'm removing it 
>> from that directory, because all it ever does is confuse people -- it really 
>> doesn't belong there.  messenger.py is a library for writing JSON messenger 
>> *clients* (external programs) in Python.  That may be useful to you, but you 
>> don't need it for the NOX side of things.
>> 
>> Hope that helps.
>> 
>> -- Murphy
>> 
>> On Jan 24, 2012, at 4:12 AM, Giorgio Mazza wrote:
>> 
>>> Thank you.
>>> I try to sum up the operations I need to perform, to see if I understood 
>>> correctly.
>>> Basically in my external application I have to set up a socket that sends 
>>> json messages and this would be quite simple.
>>> In my nox component, instead, I have to import the "JSONMsg_event" and, 
>>> within the "install()" instruction, to handle it with my specific method, 
>>> that, in my case, would only save these json messages into a dictionary, 
>>> for using them later, according to some conditions.
>>> Is that correct?
>>> 
>>> A couple of things that I didn't understand:
>>> - I assume I also have to set up a server socket in my nox component, in 
>>> order to receive json messages and handle  JSONMsg_events. So, I think this 
>>> socket has to be already up and running when I handle the event. So, when 
>>> do I have to create it and how? Do I have to use messenger.py channel class?
>>> - Second question, probably related to the first. I think to be pretty 
>>> confused about jsonmessenger: what are the jsonmessenger files I could look 
>>> into in order to understand fields and methods that I would need to use? 
>>> Are the jsonmessenger.cc and jsonmessenger.hh in 
>>> nox/src/nox/coreapps/messenger? And, if it is the case, how can I integrate 
>>> them into a python component?
>>> 
>>> Thanks again,
>>> 
>>> Giorgio
>>> 
>>> On 24/01/2012 12:28, Kyriakos Zarifis wrote:
 
 Hi Giorgio,
 
 yes, I think using jsonmessenger would be the best approach for this.
 
 you need to implement a send/receive interface on the external application 
 and in your nox component. For the external application, it's pretty 
 straightforward - Connect to the jsonmessenger socket and send json 
 strings. In your nox application you need to register for JSON messages, 
 and handle them appropriately. 
 
 The wiki explains the communication in a few steps (specifically for the 
 GUI<->NOX, but it will be similar and simpler for any external app) here:
 
 If you want to see a full example, the GUI and the monitoring component in 
 destiny could be a place to look. I'm afraid it's much more complex than 
 what you need, but the bits you need are in there if you dig in the code a 
 bit.
 
 
 On Tue, Jan 24, 2012 at 2:16 AM, Giorgio Mazza 
  wrote:
 Hi all!
 I have written a simple component in python that works fine.
 Now I would to improve it, making it to install flow entries depending on 
 parameters received from 

Re: [nox-dev] Receiving JSON messages

2012-01-26 Thread Giorgio Mazza

Thanks, I think I will specify a port.

Another question...
At the moment I get an error while importing the JSON_Msg event in the 
install() of my component.


"in install
from nox.coreapps.messenger.pymsgevent import JSONMsg_event
ImportError: No module named pymsgevent "

I blindly followed your instructions at first, but then I looked in my 
messenger folder without finding where this event is defined.
Could you please tell me where is it, so that I can insert the correct 
path in my install function? I'm using the standard message folder.

Thank you.
Regards,

Giorgio

On 25/01/2012 22:28, Murphy McCauley wrote:
I believe it defaults to port 2703.  You should be able to set the 
port number by specifying it on the commandline...

./nox_core -i ptcp: jsonmessenger=tcpport=4096 your_app_here

It listens on all IP addresses; there is currently no way to specify 
just one.


-- Murphy

On Jan 25, 2012, at 1:11 PM, Giorgio Mazza wrote:


A question about the socket opened when invoking jsonmessenger.
What are the IP address, the tcp port and the interface that this 
socket refers to? Is there any way to set them?
I undersotood the mechanism, but I don't know where to send my 
messages from the external application.

Thank you.
Regards,

Giorgio

On 24/01/2012 13:49, Murphy McCauley wrote:

The minimum to get up and going should be something like this:

1) In your component's install function:
from nox.coreapps.messenger.pymsgevent import JSONMsg_event
JSONMsg_event.register_event_converter(self.ctxt)
self.register_handler(JSONMsg_event.static_get_name(), myHandler)

2) Implement a handler:
def myHandler (e):
  import json
  print json.loads(e.jsonstring)
  e.reply(json.dumps({"msg":"Hello world"}))

3) Include jsonmessenger on the commandline or as a dependency


That may not be exactly correct -- it's adapted from a quick writeup 
I did in December about using the new Python support for the 
"regular" messenger (as opposed to the JSON messenger), which has 
not yet been pushed to the repository.  For reference, that post was:

http://noxrepo.org/pipermail/nox-dev/2011-December/008382.html

(If using the new version of messenger that I linked to in that 
post, you remove the register_event_converter() call from step 1 and 
include pyjsonmessenger instead of jsonmessenger in step 3.)


Invoking the jsonmessenger component (on the commandline or by 
including it as a dependency in your app's meta.json) will create 
the server socket for you.


You absolutely do not have to use the messenger.py class.  I'm 
removing it from that directory, because all it ever does is confuse 
people -- it really doesn't belong there.  messenger.py is a library 
for writing JSON messenger *clients* (external programs) in Python. 
 That may be useful to you, but you don't need it for the NOX side 
of things.


Hope that helps.

-- Murphy

On Jan 24, 2012, at 4:12 AM, Giorgio Mazza wrote:


Thank you.
I try to sum up the operations I need to perform, to see if I 
understood correctly.
Basically in my external application I have to set up a socket that 
sends json messages and this would be quite simple.
In my nox component, instead, I have to import the "JSONMsg_event" 
and, within the "install()" instruction, to handle it with my 
specific method, that, in my case, would only save these json 
messages into a dictionary, for using them later, according to some 
conditions.

Is that correct?

A couple of things that I didn't understand:
- I assume I also have to set up a server socket in my nox 
component, in order to receive json messages and handle  
JSONMsg_events. So, I think this socket has to be already up and 
running when I handle the event. So, when do I have to create it 
and how? Do I have to use messenger.py channel class?
- Second question, probably related to the first. I think to be 
pretty confused about jsonmessenger: what are the jsonmessenger 
files I could look into in order to understand fields and methods 
that I would need to use? Are the jsonmessenger.cc and 
jsonmessenger.hh in nox/src/nox/coreapps/messenger? And, if it is 
the case, how can I integrate them into a python component?


Thanks again,

Giorgio

On 24/01/2012 12:28, Kyriakos Zarifis wrote:

Hi Giorgio,

yes, I think using jsonmessenger would be the best approach for this.

you need to implement a send/receive interface on the external 
application and in your nox component. For the external 
application, it's pretty straightforward - Connect to the 
jsonmessenger socket and send json strings. In your nox 
application you need to register for JSON messages, and handle 
them appropriately.


The wiki explains the communication in a few steps (specifically 
for the GUI<->NOX, but it will be similar and simpler for any 
external app) here 
:


If you want to see a full example, the GUI 
 and the monitoring 


Re: [nox-dev] Receiving JSON messages

2012-01-26 Thread Murphy McCauley
Oops, that was my bad -- as I said, I had adapted that from another message.
The correct import should be:
from nox.coreapps.messenger.pyjsonmsgevent import JSONMsg_event

-- Murphy

On Jan 26, 2012, at 3:40 AM, Giorgio Mazza wrote:

> Thanks, I think I will specify a port.
> 
> Another question...
> At the moment I get an error while importing the JSON_Msg event in the 
> install() of my component.
> 
> "in install
> from nox.coreapps.messenger.pymsgevent import JSONMsg_event
> ImportError: No module named pymsgevent "
> 
> I blindly followed your instructions at first, but then I looked in my 
> messenger folder without finding where this event is defined.
> Could you please tell me where is it, so that I can insert the correct path 
> in my install function? I'm using the standard message folder.
> Thank you. 
> Regards,
> 
> Giorgio
> 
> On 25/01/2012 22:28, Murphy McCauley wrote:
>> 
>> I believe it defaults to port 2703.  You should be able to set the port 
>> number by specifying it on the commandline...
>> ./nox_core -i ptcp: jsonmessenger=tcpport=4096 your_app_here
>> 
>> It listens on all IP addresses; there is currently no way to specify just 
>> one.
>> 
>> -- Murphy
>> 
>> On Jan 25, 2012, at 1:11 PM, Giorgio Mazza wrote:
>> 
>>> A question about the socket opened when invoking jsonmessenger.
>>> What are the IP address, the tcp port and the interface that this socket 
>>> refers to? Is there any way to set them?
>>> I undersotood the mechanism, but I don't know where to send my messages 
>>> from the external application.
>>> Thank you.
>>> Regards,
>>> 
>>> Giorgio
>>> 
>>> On 24/01/2012 13:49, Murphy McCauley wrote:
 
 The minimum to get up and going should be something like this:
 
 1) In your component's install function:
 from nox.coreapps.messenger.pymsgevent import JSONMsg_event
 JSONMsg_event.register_event_converter(self.ctxt)
 self.register_handler(JSONMsg_event.static_get_name(), myHandler)
 
 2) Implement a handler:
 def myHandler (e):
   import json
   print json.loads(e.jsonstring)
   e.reply(json.dumps({"msg":"Hello world"}))
 
 3) Include jsonmessenger on the commandline or as a dependency
 
 
 That may not be exactly correct -- it's adapted from a quick writeup I did 
 in December about using the new Python support for the "regular" messenger 
 (as opposed to the JSON messenger), which has not yet been pushed to the 
 repository.  For reference, that post was:
 http://noxrepo.org/pipermail/nox-dev/2011-December/008382.html
 
 (If using the new version of messenger that I linked to in that post, you 
 remove the register_event_converter() call from step 1 and include 
 pyjsonmessenger instead of jsonmessenger in step 3.)
 
 Invoking the jsonmessenger component (on the commandline or by including 
 it as a dependency in your app's meta.json) will create the server socket 
 for you.
 
 You absolutely do not have to use the messenger.py class.  I'm removing it 
 from that directory, because all it ever does is confuse people -- it 
 really doesn't belong there.  messenger.py is a library for writing JSON 
 messenger *clients* (external programs) in Python.  That may be useful to 
 you, but you don't need it for the NOX side of things.
 
 Hope that helps.
 
 -- Murphy
 
 On Jan 24, 2012, at 4:12 AM, Giorgio Mazza wrote:
 
> Thank you.
> I try to sum up the operations I need to perform, to see if I understood 
> correctly.
> Basically in my external application I have to set up a socket that sends 
> json messages and this would be quite simple.
> In my nox component, instead, I have to import the "JSONMsg_event" and, 
> within the "install()" instruction, to handle it with my specific method, 
> that, in my case, would only save these json messages into a dictionary, 
> for using them later, according to some conditions.
> Is that correct?
> 
> A couple of things that I didn't understand:
> - I assume I also have to set up a server socket in my nox component, in 
> order to receive json messages and handle  JSONMsg_events. So, I think 
> this socket has to be already up and running when I handle the event. So, 
> when do I have to create it and how? Do I have to use messenger.py 
> channel class?
> - Second question, probably related to the first. I think to be pretty 
> confused about jsonmessenger: what are the jsonmessenger files I could 
> look into in order to understand fields and methods that I would need to 
> use? Are the jsonmessenger.cc and jsonmessenger.hh in 
> nox/src/nox/coreapps/messenger? And, if it is the case, how can I 
> integrate them into a python component?
> 
> Thanks again,
> 
> Giorgio
> 
> On 24/01/2012 12:28, Kyriakos Zarifis wrote:
>> 
>> Hi Giorgio

Re: [nox-dev] Receiving JSON messages

2012-01-26 Thread Giorgio Mazza
Actually I get the same error, because I do not have neither 
pyjsonmsgevent nor pymsgevent in messenger folder...

This is the list of what I have in messenger folder:

giorgio@controller:~/nox/build/src$ ls -a  nox/coreapps/messenger/
. jsonmessenger.la
 messenger.la
..jsonmessenger_la-jsonmessenger.lo   
messenger_la-messenger.lo
cacert.pem.libs
  messenger.py
.deps Makefile 
   meta.json
__init__.py  messenger_core.la   
servercert.pem

__init__.pycmessenger_core_la-messenger_core.lo   serverkey.pem


Do I miss anything in my folders or did I make something wrong?

Giorgio

On 26/01/2012 13:05, Murphy McCauley wrote:
Oops, that was my bad -- as I said, I had adapted that from another 
message.

The correct import should be:
from nox.coreapps.messenger.pyjsonmsgevent import JSONMsg_event

-- Murphy

On Jan 26, 2012, at 3:40 AM, Giorgio Mazza wrote:


Thanks, I think I will specify a port.

Another question...
At the moment I get an error while importing the JSON_Msg event in 
the install() of my component.


"in install
from nox.coreapps.messenger.pymsgevent import JSONMsg_event
ImportError: No module named pymsgevent "

I blindly followed your instructions at first, but then I looked in 
my messenger folder without finding where this event is defined.
Could you please tell me where is it, so that I can insert the 
correct path in my install function? I'm using the standard message 
folder.

Thank you.
Regards,

Giorgio

On 25/01/2012 22:28, Murphy McCauley wrote:
I believe it defaults to port 2703.  You should be able to set the 
port number by specifying it on the commandline...

./nox_core -i ptcp: jsonmessenger=tcpport=4096 your_app_here

It listens on all IP addresses; there is currently no way to specify 
just one.


-- Murphy

On Jan 25, 2012, at 1:11 PM, Giorgio Mazza wrote:


A question about the socket opened when invoking jsonmessenger.
What are the IP address, the tcp port and the interface that this 
socket refers to? Is there any way to set them?
I undersotood the mechanism, but I don't know where to send my 
messages from the external application.

Thank you.
Regards,

Giorgio

On 24/01/2012 13:49, Murphy McCauley wrote:

The minimum to get up and going should be something like this:

1) In your component's install function:
from nox.coreapps.messenger.pymsgevent import JSONMsg_event
JSONMsg_event.register_event_converter(self.ctxt)
self.register_handler(JSONMsg_event.static_get_name(), myHandler)

2) Implement a handler:
def myHandler (e):
  import json
  print json.loads(e.jsonstring)
  e.reply(json.dumps({"msg":"Hello world"}))

3) Include jsonmessenger on the commandline or as a dependency


That may not be exactly correct -- it's adapted from a quick 
writeup I did in December about using the new Python support for 
the "regular" messenger (as opposed to the JSON messenger), which 
has not yet been pushed to the repository.  For reference, that 
post was:

http://noxrepo.org/pipermail/nox-dev/2011-December/008382.html

(If using the new version of messenger that I linked to in that 
post, you remove the register_event_converter() call from step 1 
and include pyjsonmessenger instead of jsonmessenger in step 3.)


Invoking the jsonmessenger component (on the commandline or by 
including it as a dependency in your app's meta.json) will create 
the server socket for you.


You absolutely do not have to use the messenger.py class.  I'm 
removing it from that directory, because all it ever does is 
confuse people -- it really doesn't belong there.  messenger.py is 
a library for writing JSON messenger *clients* (external programs) 
in Python.  That may be useful to you, but you don't need it for 
the NOX side of things.


Hope that helps.

-- Murphy

On Jan 24, 2012, at 4:12 AM, Giorgio Mazza wrote:


Thank you.
I try to sum up the operations I need to perform, to see if I 
understood correctly.
Basically in my external application I have to set up a socket 
that sends json messages and this would be quite simple.
In my nox component, instead, I have to import the 
"JSONMsg_event" and, within the "install()" instruction, to 
handle it with my specific method, that, in my case, would only 
save these json messages into a dictionary, for using them later, 
according to some conditions.

Is that correct?

A couple of things that I didn't understand:
- I assume I also have to set up a server socket in my nox 
component, in order to receive json messages and handle  
JSONMsg_events. So, I think this socket has to be already up and 
running when I handle the event. So, when do I have to create it 
and how? Do I have to use messenger.py channel class?
- Second question, probably related to the first. I think to be 
pretty co

Re: [nox-dev] Receiving JSON messages

2012-01-26 Thread Kyriakos Zarifis
Hi Girogio,

I forgot to ask, but, are you using the destiny branch or zaku? It looks
like you're using zaku.

In your _source_ directory, not the build dir,  (so:
nox/src/nox/coreapps/messenger), you should have a file called
"jsonmsg_event.i", which creates the module you're missing. That exists
only in destiny

On Thu, Jan 26, 2012 at 5:27 AM, Giorgio Mazza
wrote:

> **
> Actually I get the same error, because I do not have neither
> pyjsonmsgevent nor pymsgevent in messenger folder...
> This is the list of what I have in messenger folder:
>
> giorgio@controller:~/nox/build/src$ ls -a  nox/coreapps/messenger/
> . jsonmessenger.la
>  messenger.la
> ..jsonmessenger_la-jsonmessenger.lo
> messenger_la-messenger.lo
> cacert.pem.libs
>   messenger.py
> .deps Makefile
>meta.json
> __init__.py  messenger_core.la
> servercert.pem
> __init__.pycmessenger_core_la-messenger_core.lo   serverkey.pem
>
>
> Do I miss anything in my folders or did I make something wrong?
>
> Giorgio
>
>
> On 26/01/2012 13:05, Murphy McCauley wrote:
>
> Oops, that was my bad -- as I said, I had adapted that from another
> message.
> The correct import should be:
> from nox.coreapps.messenger.pyjsonmsgevent import JSONMsg_event
>
>  -- Murphy
>
>  On Jan 26, 2012, at 3:40 AM, Giorgio Mazza wrote:
>
>  Thanks, I think I will specify a port.
>
> Another question...
> At the moment I get an error while importing the JSON_Msg event in the
> install() of my component.
>
> "in install
> from nox.coreapps.messenger.pymsgevent import JSONMsg_event
> ImportError: No module named pymsgevent "
>
> I blindly followed your instructions at first, but then I looked in my
> messenger folder without finding where this event is defined.
> Could you please tell me where is it, so that I can insert the correct
> path in my install function? I'm using the standard message folder.
> Thank you.
> Regards,
>
> Giorgio
>
> On 25/01/2012 22:28, Murphy McCauley wrote:
>
> I believe it defaults to port 2703.  You should be able to set the port
> number by specifying it on the commandline...
> ./nox_core -i ptcp: jsonmessenger=tcpport=4096 your_app_here
>
>  It listens on all IP addresses; there is currently no way to specify
> just one.
>
>  -- Murphy
>
>  On Jan 25, 2012, at 1:11 PM, Giorgio Mazza wrote:
>
>  A question about the socket opened when invoking jsonmessenger.
> What are the IP address, the tcp port and the interface that this socket
> refers to? Is there any way to set them?
> I undersotood the mechanism, but I don't know where to send my messages
> from the external application.
> Thank you.
> Regards,
>
> Giorgio
>
> On 24/01/2012 13:49, Murphy McCauley wrote:
>
> The minimum to get up and going should be something like this:
>
>  1) In your component's install function:
> from nox.coreapps.messenger.pymsgevent import JSONMsg_event
> JSONMsg_event.register_event_converter(self.ctxt)
> self.register_handler(JSONMsg_event.static_get_name(), myHandler)
>
>  2) Implement a handler:
> def myHandler (e):
>   import json
>   print json.loads(e.jsonstring)
>   e.reply(json.dumps({"msg":"Hello world"}))
>
>  3) Include jsonmessenger on the commandline or as a dependency
>
>
>  That may not be exactly correct -- it's adapted from a quick writeup I
> did in December about using the new Python support for the "regular"
> messenger (as opposed to the JSON messenger), which has not yet been pushed
> to the repository.  For reference, that post was:
> http://noxrepo.org/pipermail/nox-dev/2011-December/008382.html
>
>  (If using the new version of messenger that I linked to in that post,
> you remove the register_event_converter() call from step 1 and include
> pyjsonmessenger instead of jsonmessenger in step 3.)
>
>  Invoking the jsonmessenger component (on the commandline or by including
> it as a dependency in your app's meta.json) will create the server socket
> for you.
>
>  You absolutely do not have to use the messenger.py class.  I'm removing
> it from that directory, because all it ever does is confuse people -- it
> really doesn't belong there.  messenger.py is a library for writing JSON
> messenger *clients* (external programs) in Python.  That may be useful to
> you, but you don't need it for the NOX side of things.
>
>  Hope that helps.
>
>  -- Murphy
>
>  On Jan 24, 2012, at 4:12 AM, Giorgio Mazza wrote:
>
>  Thank you.
> I try to sum up the operations I need to perform, to see if I understood
> correctly.
> Basically in my external application I have to set up a socket that sends
> json messages and this would be quite simple.
> In my nox component, instead, I have to import the "JSONMsg_event" and,
> within the "install()" instruction, to handle it with my specific method,
> that, in my case, would only save these json messages into a dictionary,
> for using them later, according to some conditions.
> Is that correct?
>
> A coup

Re: [nox-dev] Receiving JSON messages

2012-01-26 Thread Giorgio Mazza

Yes, I'm using zaku...
And I do not have any file called "jsonmsg_event.i".
Any idea about how can I receive json messages and handle them in order 
to install flow entries?

Do I have to use destiny branch?
I don't know if it could be simple to switch from zaku to destiny, but 
i'd rather to keep zaku, as I already worked a bit on it in order to 
extend it with other classes and with the component I am try to improve.

Is it possible to implement those functionalities going on with zaku?

Giorgio

On 26/01/2012 21:38, Kyriakos Zarifis wrote:

Hi Girogio,

I forgot to ask, but, are you using the destiny branch or zaku? It 
looks like you're using zaku.


In your _source_ directory, not the build dir,  (so: 
nox/src/nox/coreapps/messenger), you should have a file called 
"jsonmsg_event.i", which creates the module you're missing. That 
exists only in destiny


On Thu, Jan 26, 2012 at 5:27 AM, Giorgio Mazza 
mailto:giorgio.mazza...@gmail.com>> wrote:


Actually I get the same error, because I do not have neither
pyjsonmsgevent nor pymsgevent in messenger folder...
This is the list of what I have in messenger folder:

giorgio@controller:~/nox/build/src$ ls -a  nox/coreapps/messenger/
. jsonmessenger.la  messenger.la

..jsonmessenger_la-jsonmessenger.lo  
messenger_la-messenger.lo
cacert.pem.libs 
messenger.py
.deps Makefile
   meta.json

__init__.py messenger_core.la
  
servercert.pem
__init__.pycmessenger_core_la-messenger_core.lo  
serverkey.pem



Do I miss anything in my folders or did I make something wrong?

Giorgio


On 26/01/2012 13:05, Murphy McCauley wrote:

Oops, that was my bad -- as I said, I had adapted that from
another message.
The correct import should be:
from nox.coreapps.messenger.pyjsonmsgevent import JSONMsg_event

-- Murphy

On Jan 26, 2012, at 3:40 AM, Giorgio Mazza wrote:


Thanks, I think I will specify a port.

Another question...
At the moment I get an error while importing the JSON_Msg event
in the install() of my component.

"in install
from nox.coreapps.messenger.pymsgevent import JSONMsg_event
ImportError: No module named pymsgevent "

I blindly followed your instructions at first, but then I looked
in my messenger folder without finding where this event is defined.
Could you please tell me where is it, so that I can insert the
correct path in my install function? I'm using the standard
message folder.
Thank you.
Regards,

Giorgio

On 25/01/2012 22:28, Murphy McCauley wrote:

I believe it defaults to port 2703.  You should be able to set
the port number by specifying it on the commandline...
./nox_core -i ptcp: jsonmessenger=tcpport=4096 your_app_here

It listens on all IP addresses; there is currently no way to
specify just one.

-- Murphy

On Jan 25, 2012, at 1:11 PM, Giorgio Mazza wrote:


A question about the socket opened when invoking jsonmessenger.
What are the IP address, the tcp port and the interface that
this socket refers to? Is there any way to set them?
I undersotood the mechanism, but I don't know where to send my
messages from the external application.
Thank you.
Regards,

Giorgio

On 24/01/2012 13:49, Murphy McCauley wrote:

The minimum to get up and going should be something like this:

1) In your component's install function:
from nox.coreapps.messenger.pymsgevent import JSONMsg_event
JSONMsg_event.register_event_converter(self.ctxt)
self.register_handler(JSONMsg_event.static_get_name(), myHandler)

2) Implement a handler:
def myHandler (e):
  import json
  print json.loads(e.jsonstring)
  e.reply(json.dumps({"msg":"Hello world"}))

3) Include jsonmessenger on the commandline or as a dependency


That may not be exactly correct -- it's adapted from a quick
writeup I did in December about using the new Python support
for the "regular" messenger (as opposed to the JSON
messenger), which has not yet been pushed to the repository. 
For reference, that post was:

http://noxrepo.org/pipermail/nox-dev/2011-December/008382.html

(If using the new version of messenger that I linked to in
that post, you remove the register_event_converter() call
from step 1 and include pyjsonmessenger instead of
jsonmessenger in step 3.)

Invoking the jsonmessenger component (on the commandline or
by including it as a dependency in your app's meta.json) will
create the server socket for you.

You absolutely do not have to use the messenger.py class.
 I'm removing it from that dire

Re: [nox-dev] Receiving JSON messages

2012-01-26 Thread Kyriakos Zarifis
That's the reason; the jsonmsg_event isn't exposed in python on zaku.
I'd really encourage you to try to migrate to destiny. Not only because
this will work, but more importantly because destiny is a far more
developed branch by now, with many fixes and added features.

If you really don't want to switch to destiny, maybe you could just grab
jsonmsg_event.i from destiny and stick it in your zaku tree. (I can't
remember if this is going to just work or you'll need to hack something,
but give it a try and see what breaks?)

On Thu, Jan 26, 2012 at 1:37 PM, Giorgio Mazza
wrote:

> **
> Yes, I'm using zaku...
> And I do not have any file called "jsonmsg_event.i".
> Any idea about how can I receive json messages and handle them in order to
> install flow entries?
> Do I have to use destiny branch?
> I don't know if it could be simple to switch from zaku to destiny, but i'd
> rather to keep zaku, as I already worked a bit on it in order to extend it
> with other classes and with the component I am try to improve.
> Is it possible to implement those functionalities going on with zaku?
>
> Giorgio
>
>
> On 26/01/2012 21:38, Kyriakos Zarifis wrote:
>
> Hi Girogio,
>
>  I forgot to ask, but, are you using the destiny branch or zaku? It looks
> like you're using zaku.
>
>  In your _source_ directory, not the build dir,  (so:
> nox/src/nox/coreapps/messenger), you should have a file called
> "jsonmsg_event.i", which creates the module you're missing. That exists
> only in destiny
>
> On Thu, Jan 26, 2012 at 5:27 AM, Giorgio Mazza  > wrote:
>
>>  Actually I get the same error, because I do not have neither
>> pyjsonmsgevent nor pymsgevent in messenger folder...
>> This is the list of what I have in messenger folder:
>>
>> giorgio@controller:~/nox/build/src$ ls -a  nox/coreapps/messenger/
>> . jsonmessenger.la
>>  messenger.la
>> ..jsonmessenger_la-jsonmessenger.lo
>> messenger_la-messenger.lo
>> cacert.pem.libs
>>   messenger.py
>> .deps Makefile
>>meta.json
>> __init__.py  messenger_core.la
>> servercert.pem
>> __init__.pycmessenger_core_la-messenger_core.lo   serverkey.pem
>>
>>
>> Do I miss anything in my folders or did I make something wrong?
>>
>> Giorgio
>>
>>
>> On 26/01/2012 13:05, Murphy McCauley wrote:
>>
>> Oops, that was my bad -- as I said, I had adapted that from another
>> message.
>> The correct import should be:
>> from nox.coreapps.messenger.pyjsonmsgevent import JSONMsg_event
>>
>>  -- Murphy
>>
>>  On Jan 26, 2012, at 3:40 AM, Giorgio Mazza wrote:
>>
>>  Thanks, I think I will specify a port.
>>
>> Another question...
>> At the moment I get an error while importing the JSON_Msg event in the
>> install() of my component.
>>
>> "in install
>> from nox.coreapps.messenger.pymsgevent import JSONMsg_event
>> ImportError: No module named pymsgevent "
>>
>> I blindly followed your instructions at first, but then I looked in my
>> messenger folder without finding where this event is defined.
>> Could you please tell me where is it, so that I can insert the correct
>> path in my install function? I'm using the standard message folder.
>> Thank you.
>> Regards,
>>
>> Giorgio
>>
>> On 25/01/2012 22:28, Murphy McCauley wrote:
>>
>> I believe it defaults to port 2703.  You should be able to set the port
>> number by specifying it on the commandline...
>> ./nox_core -i ptcp: jsonmessenger=tcpport=4096 your_app_here
>>
>>  It listens on all IP addresses; there is currently no way to specify
>> just one.
>>
>>  -- Murphy
>>
>>  On Jan 25, 2012, at 1:11 PM, Giorgio Mazza wrote:
>>
>>  A question about the socket opened when invoking jsonmessenger.
>> What are the IP address, the tcp port and the interface that this socket
>> refers to? Is there any way to set them?
>> I undersotood the mechanism, but I don't know where to send my messages
>> from the external application.
>> Thank you.
>> Regards,
>>
>> Giorgio
>>
>> On 24/01/2012 13:49, Murphy McCauley wrote:
>>
>> The minimum to get up and going should be something like this:
>>
>>  1) In your component's install function:
>> from nox.coreapps.messenger.pymsgevent import JSONMsg_event
>> JSONMsg_event.register_event_converter(self.ctxt)
>> self.register_handler(JSONMsg_event.static_get_name(), myHandler)
>>
>>  2) Implement a handler:
>> def myHandler (e):
>>   import json
>>   print json.loads(e.jsonstring)
>>   e.reply(json.dumps({"msg":"Hello world"}))
>>
>>  3) Include jsonmessenger on the commandline or as a dependency
>>
>>
>>  That may not be exactly correct -- it's adapted from a quick writeup I
>> did in December about using the new Python support for the "regular"
>> messenger (as opposed to the JSON messenger), which has not yet been pushed
>> to the repository.  For reference, that post was:
>> http://noxrepo.org/pipermail/nox-dev/2011-December/008382.html
>>
>>  (If using the new version of messenger that I linked to in th

Re: [nox-dev] Receiving JSON messages

2012-01-27 Thread kk yap
Hi Giorgio,

Your client is disconnecting before the reply is sent.  If you look at
nox-console.py, it should be a good example to follow.

Regards
KK

On 27 January 2012 05:12, Kyriakos Zarifis  wrote:
> A JSONMsg_event is just another NOX event and us such it will either passed
> on to all components down the event handler chain or stopped by one of them.
> Your handler needs to return a valid NOX event disposition (
> http://noxrepo.org/noxwiki/index.php/Disposition  )
> So in your case you just need to add a "return STOP" and the error will
> disappear.
>
>
> As for the other comment, I'm not sure how messenger_core cleans the
> connections state/closes socket. It might very well be a timing issue, maybe
> the connection state hasn't been cleaned when the event is processed. I
> don't know if the log messages represent the reality 100%. In any case the
> last message is either never really sent or it's sent to the void. Either
> way I'd just ignore it, I doubt it will affect anything
>
>
> On Fri, Jan 27, 2012 at 3:02 AM, Giorgio Mazza 
> wrote:
>>
>> I tried this way:  I replaced zaku's default messenger folder with
>> destiny's messenger one (nox/src/nox/coreapps/messenger), that I had
>> previously downloaded and installed.
>> Then I recompiled zaku and the import error disappeared, so that when I
>> run
>> ./nox_core -v -i ptcp:6633 jsonmessenger=tcpport=3334 my_component
>> I do not get errors anymore and components are installed successfully.
>> However, when I try to send a json message from my external application I
>> get a strange behaviour. I don't understand very well what is happening and
>> why I get this error, so I do not know if it is my fault in doing something
>> or if I need to hack something because the simple replacement of messenger
>> folder is not enough.
>>
>> My callback is fairly simple for the moment and the only thing it does is
>> to store the value of the received json message and to answer with a "Hello
>> world" message, like that:
>>     def json_message_callback(self, e):
>>         import json
>>         global cache_server_table    #the global dict where I
>> want to store received json information
>>         cache_server_table = json.loads(e.jsonstring)
>>         print cache_server_table
>>
>>         e.reply(json.dumps({"msg":"Hello world"}))
>>
>>
>> This is my simple external application:
>>
>> import json
>> import socket
>>
>> HOST = '10.0.10.1'
>> PORT = 3334
>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>> s.connect((HOST, PORT))
>> print "Connected to server: " + str(s.getpeername())
>> message={"msg":"CS-setup","mac":"x","ip":"10.0.10.2"}
>> json_message=json.dumps(message)
>> s.send(json_message)
>> print "Sent JSON message"
>> data = s.recv(1024)
>> print 'Received', repr(data)
>>
>>
>> And this is what I get in the controller prompt, after executing the above
>> code:
>>
>> 00045|openflow|DBG:Passive tcp interface bound to port 6633
>> 00046|nox|INFO:nox bootstrap complete
>> 00047|messenger_core|DBG:Starting connection with idleInterval 0
>> 00048|jsonmessenger|DBG:JSON message of length 18 (connect)
>> 00049|jsonmessenger|DBG:JSON message of length 18
>> 00050|jsonmessenger|DBG:JSON: {"type":"connect"}
>> {u'type': u'connect'}
>> 00051|messenger_core|DBG:Sent string of length 22 socket 0x8b9ff48
>> 00052|pyrt|ERR:Python handler returned invalid Disposition.
>>                         < No idea
>> 00053|messenger_core|DBG:TCP socket connection accepted
>> 00054|messenger_core|DBG:Copy 54 bytes to message
>> 00055|messenger_core|DBG:Received packet of length 54
>> 00056|jsonmessenger|DBG:JSON message of length 54
>> 00057|jsonmessenger|DBG:Message posted as JSONMsg_event
>> 00058|jsonmessenger|DBG:JSON:
>> {"mac":"x","msg":"CS-setup","ip":"10.0.10.2"}
>> 00059|jsonmessenger|DBG:JSON message of length 21 (disconnect)
>> 00060|jsonmessenger|DBG:JSON message of length 21
>> 00061|messenger_core|DBG:socket closed
>> 00062|jsonmessenger|DBG:JSON: {"type":"disconnect"}
>> 00063|jsonmessenger|DBG:Clear connection state for 0x8b9ff48
>> {u'type': u'disconnect'}
>> 00064|messenger_core|DBG:Sent string of length 22 socket
>> 0x8b9ff48   <-- It seems that my
>> callback tries to answer when the socket is already closed. Why?
>> 00065|pyrt|ERR:Python handler returned invalid Disposition.
>>
>>
>> Any idea or suggestion will be appreciated.
>>
>> Regards,
>> Giorgio
>>
>>
>>
>> On 26/01/2012 23:39, Kyriakos Zarifis wrote:
>>
>> That's the reason; the jsonmsg_event isn't exposed in python on zaku.
>> I'd really encourage you to try to migrate to destiny. Not only because
>> this will work, but more importantly because destiny is a far more developed
>> branch by now, with many fixes and added features.
>>
>> If you really don't want to switch to destiny, maybe you could just grab
>> jsonmsg_event.i from destiny and stick it in your zaku tree. (I can't
>> remember if t

Re: [nox-dev] Receiving JSON messages

2012-01-29 Thread Giorgio Mazza

A little update and a further question :)

With destiny's messenger my component works, even adding jsonmessenger 
as a dependency. Also Jsonmsg_events are raised and handled without 
errors by my callback and I solved the dummy timer problem with the 
client disconnection.


Now, I have a strange behaviour with my callback that seems to handle 
only messages that have the default syntax described in jsonmessenger.hh 
( just above the definition of the jsonmessenger class).
If I send a 'connect' or a 'disconnect' message it is handled by my 
callback, while, if I send a different message (that's what I want to 
do), jsonmessenger posts a JSONMsg_event, that it is simply ignored by 
my callback.


That 's a snippet of my install function:

from nox.coreapps.messenger.pyjsonmsgevent import JSONMsg_event
JSONMsg_event.register_event_converter(self.ctxt)
self.register_handler(JSONMsg_event.static_get_name(), 
self.json_message_callback)



That's my (temporary) callback:

def json_message_callback(self, e):
import json
global cache_server_table
message = json.loads(e.jsonstring)
cache_server_table.update(message)
print message
print cache_server_table
e.reply(json.dumps({"MSG":"Welcome! I am the Controller"}))
if cache_server_table.has_key("MSG"):
print cache_server_table["MSG"]
if cache_server_table["MSG"] == "Connection setup":
cache_server_MAC = cache_server_table["MAC"]
print cache_server_MAC
return CONTINUE


And that's what I get as output:

00046|nox|INFO:nox bootstrap complete
00047|messenger_core|DBG:Starting connection with idleInterval 0
00048|jsonmessenger|DBG:JSON message of length 18 (connect)
00049|jsonmessenger|DBG:JSON message of length 18
00050|jsonmessenger|DBG:JSON: {"type":"connect"}
{u'type': u'connect'} <--- the two print instruction
{u'type': u'connect'} <--- in the callback
00051|messenger_core|DBG:Sent string of length 39 socket 0x8e536c0
00052|messenger_core|DBG:TCP socket connection accepted
00053|messenger_core|DBG:Copy 74 bytes to message
00054|messenger_core|DBG:Received packet of length 74
00055|jsonmessenger|DBG:JSON message of length 74
00056|jsonmessenger|DBG:Message posted as JSONMsg_event 
<- after that I would expect the 
output of my callback (the two print instruction)
00057|jsonmessenger|DBG:JSON: 
{"MAC":"08:00:27:cc:77:1c","IP":"10.0.10.2","MSG":"Connection setup"}

00058|messenger_core|DBG:Copy 22 bytes to message
00059|messenger_core|DBG:Received packet of length 22
00060|jsonmessenger|DBG:JSON message of length 22
00061|jsonmessenger|DBG:Message posted as JSONMsg_event
00062|jsonmessenger|DBG:JSON: {"type":"disconnect"}
00063|jsonmessenger|DBG:Clear connection state for 0x8e536c0
{u'type': u'disconnect'}
{u'type': u'disconnect'}


So, the question is: Why my callback does not handle events posted by 
jsonmessenger? How can I fix that? Is there any particular syntax I have 
to follow so that it is a json-related error?


Thanks in advance.

Regards,
Giorgio


On 27/01/2012 16:42, kk yap wrote:

Hi Giorgio,

Your client is disconnecting before the reply is sent.  If you look at
nox-console.py, it should be a good example to follow.

Regards
KK

On 27 January 2012 05:12, Kyriakos Zarifis  wrote:

A JSONMsg_event is just another NOX event and us such it will either passed
on to all components down the event handler chain or stopped by one of them.
Your handler needs to return a valid NOX event disposition (
http://noxrepo.org/noxwiki/index.php/Disposition  )
So in your case you just need to add a "return STOP" and the error will
disappear.


As for the other comment, I'm not sure how messenger_core cleans the
connections state/closes socket. It might very well be a timing issue, maybe
the connection state hasn't been cleaned when the event is processed. I
don't know if the log messages represent the reality 100%. In any case the
last message is either never really sent or it's sent to the void. Either
way I'd just ignore it, I doubt it will affect anything


On Fri, Jan 27, 2012 at 3:02 AM, Giorgio Mazza
wrote:

I tried this way:  I replaced zaku's default messenger folder with
destiny's messenger one (nox/src/nox/coreapps/messenger), that I had
previously downloaded and installed.
Then I recompiled zaku and the import error disappeared, so that when I
run
./nox_core -v -i ptcp:6633 jsonmessenger=tcpport=3334 my_component
I do not get errors anymore and components are installed successfully.
However, when I try to send a json message from my external application I
get a strange behaviour. I don't understand very well what is happening and
why I get this error, so I do not know if it is my fault in doing something
or if I need to hack something because the simple replacement of messenger
folder is not enough.

My callback is fairly simple for the moment and

Re: [nox-dev] Receiving JSON messages

2012-01-29 Thread kk yap
Hi,

Reading the documentation might help.
http://noxrepo.org/~yapkke/doc/classvigil_1_1jsonmessenger.html#_details

Try have a type field.

Regards
KK

On 29 January 2012 07:34, Giorgio Mazza  wrote:
> A little update and a further question :)
>
> With destiny's messenger my component works, even adding jsonmessenger as a
> dependency. Also Jsonmsg_events are raised and handled without errors by my
> callback and I solved the dummy timer problem with the client disconnection.
>
> Now, I have a strange behaviour with my callback that seems to handle only
> messages that have the default syntax described in jsonmessenger.hh ( just
> above the definition of the jsonmessenger class).
> If I send a 'connect' or a 'disconnect' message it is handled by my
> callback, while, if I send a different message (that's what I want to do),
> jsonmessenger posts a JSONMsg_event, that it is simply ignored by my
> callback.
>
> That 's a snippet of my install function:
>
> from nox.coreapps.messenger.pyjsonmsgevent import JSONMsg_event
> JSONMsg_event.register_event_converter(self.ctxt)
> self.register_handler(JSONMsg_event.static_get_name(),
> self.json_message_callback)
>
>
> That's my (temporary) callback:
>
> def json_message_callback(self, e):
>         import json
>         global cache_server_table
>         message = json.loads(e.jsonstring)
>         cache_server_table.update(message)
>         print message
>         print cache_server_table
>         e.reply(json.dumps({"MSG":"Welcome! I am the Controller"}))
>         if cache_server_table.has_key("MSG"):
>             print cache_server_table["MSG"]
>             if cache_server_table["MSG"] == "Connection setup":
>                 cache_server_MAC = cache_server_table["MAC"]
>                 print cache_server_MAC
>         return CONTINUE
>
>
> And that's what I get as output:
>
> 00046|nox|INFO:nox bootstrap complete
> 00047|messenger_core|DBG:Starting connection with idleInterval 0
> 00048|jsonmessenger|DBG:JSON message of length 18 (connect)
> 00049|jsonmessenger|DBG:JSON message of length 18
> 00050|jsonmessenger|DBG:JSON: {"type":"connect"}
> {u'type': u'connect'}
> <--- the two print instruction
> {u'type': u'connect'}
> <--- in the callback
> 00051|messenger_core|DBG:Sent string of length 39 socket 0x8e536c0
> 00052|messenger_core|DBG:TCP socket connection accepted
> 00053|messenger_core|DBG:Copy 74 bytes to message
> 00054|messenger_core|DBG:Received packet of length 74
> 00055|jsonmessenger|DBG:JSON message of length 74
> 00056|jsonmessenger|DBG:Message posted as JSONMsg_event
> <- after that I would expect the
> output of my callback (the two print instruction)
> 00057|jsonmessenger|DBG:JSON:
> {"MAC":"08:00:27:cc:77:1c","IP":"10.0.10.2","MSG":"Connection setup"}
> 00058|messenger_core|DBG:Copy 22 bytes to message
> 00059|messenger_core|DBG:Received packet of length 22
> 00060|jsonmessenger|DBG:JSON message of length 22
> 00061|jsonmessenger|DBG:Message posted as JSONMsg_event
>
> 00062|jsonmessenger|DBG:JSON: {"type":"disconnect"}
> 00063|jsonmessenger|DBG:Clear connection state for 0x8e536c0
> {u'type': u'disconnect'}
> {u'type': u'disconnect'}
>
>
> So, the question is: Why my callback does not handle events posted by
> jsonmessenger? How can I fix that? Is there any particular syntax I have to
> follow so that it is a json-related error?
>
> Thanks in advance.
>
> Regards,
> Giorgio
>
>
>
> On 27/01/2012 16:42, kk yap wrote:
>
> Hi Giorgio,
>
> Your client is disconnecting before the reply is sent.  If you look at
> nox-console.py, it should be a good example to follow.
>
> Regards
> KK
>
> On 27 January 2012 05:12, Kyriakos Zarifis  wrote:
>
> A JSONMsg_event is just another NOX event and us such it will either passed
> on to all components down the event handler chain or stopped by one of them.
> Your handler needs to return a valid NOX event disposition (
> http://noxrepo.org/noxwiki/index.php/Disposition  )
> So in your case you just need to add a "return STOP" and the error will
> disappear.
>
>
> As for the other comment, I'm not sure how messenger_core cleans the
> connections state/closes socket. It might very well be a timing issue, maybe
> the connection state hasn't been cleaned when the event is processed. I
> don't know if the log messages represent the reality 100%. In any case the
> last message is either never really sent or it's sent to the void. Either
> way I'd just ignore it, I doubt it will affect anything
>
>
> On Fri, Jan 27, 2012 at 3:02 AM, Giorgio Mazza 
> wrote:
>
> I tried this way:  I replaced zaku's default messenger folder with
> destiny's messenger one (nox/src/nox/coreapps/messenger), that I had
> previously downloaded and installed.
> Then I recompiled zaku and the import error disappeared, so that when I
> run
> ./nox_core -v -i ptcp:6633 jsonmessenger=tcpport=3334 my_component
> I do not get errors anymore and components a

Re: [nox-dev] Receiving JSON messages

2012-01-29 Thread Giorgio Mazza

It was the type field, thanks!

On 29/01/2012 16:45, kk yap wrote:

Hi,

Reading the documentation might help.
http://noxrepo.org/~yapkke/doc/classvigil_1_1jsonmessenger.html#_details

Try have a type field.

Regards
KK

On 29 January 2012 07:34, Giorgio Mazza  wrote:

A little update and a further question :)

With destiny's messenger my component works, even adding jsonmessenger as a
dependency. Also Jsonmsg_events are raised and handled without errors by my
callback and I solved the dummy timer problem with the client disconnection.

Now, I have a strange behaviour with my callback that seems to handle only
messages that have the default syntax described in jsonmessenger.hh ( just
above the definition of the jsonmessenger class).
If I send a 'connect' or a 'disconnect' message it is handled by my
callback, while, if I send a different message (that's what I want to do),
jsonmessenger posts a JSONMsg_event, that it is simply ignored by my
callback.

That 's a snippet of my install function:

from nox.coreapps.messenger.pyjsonmsgevent import JSONMsg_event
JSONMsg_event.register_event_converter(self.ctxt)
self.register_handler(JSONMsg_event.static_get_name(),
self.json_message_callback)


That's my (temporary) callback:

def json_message_callback(self, e):
 import json
 global cache_server_table
 message = json.loads(e.jsonstring)
 cache_server_table.update(message)
 print message
 print cache_server_table
 e.reply(json.dumps({"MSG":"Welcome! I am the Controller"}))
 if cache_server_table.has_key("MSG"):
 print cache_server_table["MSG"]
 if cache_server_table["MSG"] == "Connection setup":
 cache_server_MAC = cache_server_table["MAC"]
 print cache_server_MAC
 return CONTINUE


And that's what I get as output:

00046|nox|INFO:nox bootstrap complete
00047|messenger_core|DBG:Starting connection with idleInterval 0
00048|jsonmessenger|DBG:JSON message of length 18 (connect)
00049|jsonmessenger|DBG:JSON message of length 18
00050|jsonmessenger|DBG:JSON: {"type":"connect"}
{u'type': u'connect'}
<--- the two print instruction
{u'type': u'connect'}
<--- in the callback
00051|messenger_core|DBG:Sent string of length 39 socket 0x8e536c0
00052|messenger_core|DBG:TCP socket connection accepted
00053|messenger_core|DBG:Copy 74 bytes to message
00054|messenger_core|DBG:Received packet of length 74
00055|jsonmessenger|DBG:JSON message of length 74
00056|jsonmessenger|DBG:Message posted as JSONMsg_event
<- after that I would expect the
output of my callback (the two print instruction)
00057|jsonmessenger|DBG:JSON:
{"MAC":"08:00:27:cc:77:1c","IP":"10.0.10.2","MSG":"Connection setup"}
00058|messenger_core|DBG:Copy 22 bytes to message
00059|messenger_core|DBG:Received packet of length 22
00060|jsonmessenger|DBG:JSON message of length 22
00061|jsonmessenger|DBG:Message posted as JSONMsg_event

00062|jsonmessenger|DBG:JSON: {"type":"disconnect"}
00063|jsonmessenger|DBG:Clear connection state for 0x8e536c0
{u'type': u'disconnect'}
{u'type': u'disconnect'}


So, the question is: Why my callback does not handle events posted by
jsonmessenger? How can I fix that? Is there any particular syntax I have to
follow so that it is a json-related error?

Thanks in advance.

Regards,
Giorgio



On 27/01/2012 16:42, kk yap wrote:

Hi Giorgio,

Your client is disconnecting before the reply is sent.  If you look at
nox-console.py, it should be a good example to follow.

Regards
KK

On 27 January 2012 05:12, Kyriakos Zarifis  wrote:

A JSONMsg_event is just another NOX event and us such it will either passed
on to all components down the event handler chain or stopped by one of them.
Your handler needs to return a valid NOX event disposition (
http://noxrepo.org/noxwiki/index.php/Disposition  )
So in your case you just need to add a "return STOP" and the error will
disappear.


As for the other comment, I'm not sure how messenger_core cleans the
connections state/closes socket. It might very well be a timing issue, maybe
the connection state hasn't been cleaned when the event is processed. I
don't know if the log messages represent the reality 100%. In any case the
last message is either never really sent or it's sent to the void. Either
way I'd just ignore it, I doubt it will affect anything


On Fri, Jan 27, 2012 at 3:02 AM, Giorgio Mazza
wrote:

I tried this way:  I replaced zaku's default messenger folder with
destiny's messenger one (nox/src/nox/coreapps/messenger), that I had
previously downloaded and installed.
Then I recompiled zaku and the import error disappeared, so that when I
run
./nox_core -v -i ptcp:6633 jsonmessenger=tcpport=3334 my_component
I do not get errors anymore and components are installed successfully.
However, when I try to send a json message from my external application I
get a strange behaviour. I don'