work in progress: agent.talk - client connect basically working

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3290 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2009-03-22 15:58:40 +00:00
parent e43810beb2
commit fa7f9f3d3f
2 changed files with 10 additions and 5 deletions

View file

@ -39,6 +39,7 @@ class Session(object):
self.subscriber = subscriber
self.url = url
self.state = 'logon'
self.sending = False
self.queue = []
self.interactions = {}
@ -46,22 +47,24 @@ class Session(object):
data = json.loads(data)
self.state = 'open'
self.subscriber.onMessage(None, data)
self.sending = False
self._processQueue()
# self._poll()
def received(self, data):
data = json.loads(data)
# TODO: check data
self.sending = False
self._processQueue()
def pollReceived(self, data):
data = json.loads(data)
if data.get('action') != 'idle':
self.subscriber.onMessage(None, data)
self.subscriber.onMessage(interaction, data)
# self._poll()
def _send(self, data, interaction):
if self.queue:
if self.sending or self.queue:
self.queue.append(data)
else:
self._sendData(data)
@ -69,9 +72,11 @@ class Session(object):
def _processQueue(self):
if not self.queue:
return
self._sendData(self.queue.pop(0))
def _sendData(self, data):
content = dict(id=self.id, command='send', data=data)
def _sendData(self, data, command='send'):
self.sending = True
content = dict(id=self.id, command=command, data=data)
d = getPage(self.url, postdata=json.dumps(content))
d.addCallback(s.received)

View file

@ -105,7 +105,7 @@ class ISession(Interface):
manager = Attribute("""The server or client object, respectively, that
created the session.""")
subscriber = Attribute("The subscriber that initiated the session.")
url = Attribute("The URL of the server the session connects to.")
url = Attribute("The URL of the server (or client) the session connects to.")
state = Attribute("""A string specifying the current state of the session:
'logon': The remote client is trying to connect/log in,
data may contain credential information;