Skip to content
This repository has been archived by the owner on Nov 23, 2020. It is now read-only.

connection_made method didn't invoked #148

Closed
nmg1986 opened this issue Jul 1, 2015 · 7 comments
Closed

connection_made method didn't invoked #148

nmg1986 opened this issue Jul 1, 2015 · 7 comments
Labels

Comments

@nmg1986
Copy link

nmg1986 commented Jul 1, 2015

the connection_made method of class ProtocolConsumer didn't invoked when the connection is made. such as - telnet localhost 8060

@lsbardel
Copy link
Member

lsbardel commented Jul 1, 2015

Where is the code and the test case to reproduce your issue!?

@nmg1986
Copy link
Author

nmg1986 commented Jul 1, 2015

the code from the echo server examples:
https://github.com/quantmind/pulsar/blob/master/examples/echo/manage.py

and i add the connection_made method for class EchoProtocol as follows:

class EchoProtocol(pulsar.ProtocolConsumer):
'''An echo :class:~.ProtocolConsumer for client and servers.

The only difference between client and server is the implementation
of the :meth:`response` method.
'''
separator = b'\r\n\r\n'
'''A separator for messages.'''
buffer = b''
'''The buffer for long messages'''

def connection_made(self, connection):
    self.logger.info('connected')

when i run the server and telnet from another terminal, when connected, the connection_made method do noting!

@lsbardel
Copy link
Member

lsbardel commented Jul 1, 2015

The connection_made in the ProtocolConsumer is fired when the Connection (the protocol) creates a new consumer, i.e. when it needs to build the consumer to consume data received from the connection transport.

Therefore, simply connecting won't fire and connection_made event on the ProtocolConsumer but it will fire a connection_made event on the Connection.

Try sending a message and you should see the event fired.

To have connection_made event on the Connection, you need to add handler to it rather than the ProtocolConsumer.

@nmg1986
Copy link
Author

nmg1986 commented Jul 1, 2015

you mean class EchoProtocol(pulsar.async.events.EventHandler): ?

@nmg1986
Copy link
Author

nmg1986 commented Jul 1, 2015

when i use class EchoProtocol(asyncio.Protocol): , it still does not work:(, can you give some examples for this ?

lsbardel added a commit that referenced this issue Jul 1, 2015
@lsbardel
Copy link
Member

lsbardel commented Jul 1, 2015

There was a small bug which I've fixed.
I've updated the example, it should display the message on connection_made event.
Note, fix is in the dev branch

@nmg1986
Copy link
Author

nmg1986 commented Jul 2, 2015

Yes, the updated example works well, but how can i do connection_made and connection_lost in ProtocolConsumer not outside?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants