# NetMessenger

from direct.distributed.NetMessenger import NetMessenger

This works very much like the Messenger class except that messages are sent over the network and (possibly) handled (accepted) on a remote machine (server).

## Inheritance:

NetMessenger: Messenger
Messenger:

## Methods of NetMessenger:

__init__
clear
handle
send

## Methods of Messenger:

__dispatch
__eventRepr
__init__
__lockAndDispatch
__methodRepr
__repr__
_getEvents
_getMessengerId
_getNumListeners
_getObject
_getObjects
_releaseObject
_storeObject
accept
clear
detailedRepr
find
findAll
getAllAccepting
getEvents
ignore
ignoreAll
isAccepting
isEmpty
isIgnoring
replaceMethod
send
toggleVerbose
whoAccepts

__init__ def __init__(self, air, channels) air is the AI Repository. channels is a list of channel IDs (uint32 values)

clear def clear(self) Undocumented function.

handle def handle(self, pickleData) Send pickleData from the net on the local netMessenger. The internal data in pickleData should have a tuple of (messageString, sendArgsList).

send def send(self, message, sentArgs=[]) Send message to All AI and Uber Dog servers.

__dispatch def __dispatch(self, acceptorDict, event, sentArgs, foundWatch) Undocumented function.

__eventRepr def __eventRepr(self, event) Compact version of event, acceptor pairs

__init__ def __init__(self) One is keyed off the event name. It has the following structure: {event1: {object1: [method, extraArgs, persistent], object2: [method, extraArgs, persistent]}, event2: {object1: [method, extraArgs, persistent], object2: [method, extraArgs, persistent]}} This dictionary allow for efficient callbacks when the messenger hears an event. A second dictionary remembers which objects are accepting which events. This allows for efficient ignoreAll commands. Or, for an example with more real data: {'mouseDown': {avatar: [avatar.jump, [2.0], 1]}}

__lockAndDispatch def __lockAndDispatch(self, acceptorDict, event, sentArgs, foundWatch) Undocumented function.

__methodRepr def __methodRepr(self, method) return string version of class.method or method.

__repr__ def __repr__(self) Compact version of event, acceptor pairs

_getEvents def _getEvents(self) Undocumented function.

_getMessengerId def _getMessengerId(self, object) Undocumented function.

_getNumListeners def _getNumListeners(self, event) Undocumented function.

_getObject def _getObject(self, id) Undocumented function.

_getObjects def _getObjects(self) Undocumented function.

_releaseObject def _releaseObject(self, object) Undocumented function.

_storeObject def _storeObject(self, object) Undocumented function.

accept def accept(self, event, object, method, extraArgs=[], persistent=1) accept(self, string, DirectObject, Function, List, Boolean) Make this object accept this event. When the event is sent (using Messenger.send or from C++), method will be executed, optionally passing in extraArgs. If the persistent flag is set, it will continue to respond to this event, otherwise it will respond only once.

clear def clear(self) Start fresh with a clear dict

detailedRepr def detailedRepr(self) Print out the table in a detailed readable format

find def find(self, needle) return a matching event (needle) if found (in haystack). This is primarily a debugging tool.

findAll def findAll(self, needle, limit=None) return a dict of events (needle) if found (in haystack). limit may be None or an integer (e.g. 1). This is primarily a debugging tool.

getAllAccepting def getAllAccepting(self, object) Returns the list of all events accepted by the indicated object.

getEvents def getEvents(self) Undocumented function.

ignore def ignore(self, event, object) ignore(self, string, DirectObject) Make this object no longer respond to this event. It is safe to call even if it was not already accepting

ignoreAll def ignoreAll(self, object) Make this object no longer respond to any events it was accepting Useful for cleanup

isAccepting def isAccepting(self, event, object) isAccepting(self, string, DirectOject) Is this object accepting this event?

isEmpty def isEmpty(self) Undocumented function.

isIgnoring def isIgnoring(self, event, object) isIgnorning(self, string, DirectObject) Is this object ignoring this event?

replaceMethod def replaceMethod(self, oldMethod, newFunction) This is only used by Finder.py - the module that lets you redefine functions with Control-c-Control-v

send def send(self, event, sentArgs=[], taskChain=None) Send this event, optionally passing in arguments event is usually a string. sentArgs is a list of any data that you want passed along to the handlers listening to this event. If taskChain is not None, it is the name of the task chain which should receive the event. If taskChain is None, the event is handled immediately. Setting a non-None taskChain will defer the event (possibly till next frame or even later) and create a new, temporary task within the named taskChain, but this is the only way to send an event across threads.

toggleVerbose def toggleVerbose(self) Undocumented function.

whoAccepts def whoAccepts(self, event) Return objects accepting the given event