Bill Kelly
2008-Apr-30 12:41 UTC
[Eventmachine-talk] get_peername - start_server vs. connect
Hi, On windows, get_peername works both with connections obtained via start_server, and connections obtained via connect. On linux, get_peername seems to only work with connections obtained via start_server. (I''m using svn HEAD.) I''m wondering which is the intended behavior? (I realize get_peername is less useful for connections obtained via connect, since one should already know the IP/port to which the connection was made. However, I have a symmetric protocol, which uses the same handler for the "client" and "server", so it''s convenient to have get_peername "just work.") Regards, Bill
Roger Pack
2008-Apr-30 14:58 UTC
[Eventmachine-talk] get_peername - start_server vs. connect
have the connections been successfully connected before you call peername? On Wed, Apr 30, 2008 at 1:41 PM, Bill Kelly <billk at cts.com> wrote:> Hi, > > On windows, get_peername works both with connections obtained > via start_server, and connections obtained via connect. > > On linux, get_peername seems to only work with connections > obtained via start_server. > > (I''m using svn HEAD.) > > I''m wondering which is the intended behavior? > > (I realize get_peername is less useful for connections obtained > via connect, since one should already know the IP/port to which > the connection was made. However, I have a symmetric protocol, > which uses the same handler for the "client" and "server", so > it''s convenient to have get_peername "just work.") > > > Regards, > > Bill > > > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talk >
Bill Kelly
2008-Apr-30 16:47 UTC
[Eventmachine-talk] get_peername - start_server vs. connect
From: "Roger Pack" <rogerpack2005 at gmail.com>> > have the connections been successfully connected before you call peername?I presume so. I''m making the call from the post_init method. Strange. I tried to write a very minimal bit of code to reproduce the problem and wasn''t able to. I do still see the problem in the following code, but only on Linux, not on Windows: http://tastyspleen.net/~billk/ruby/retardbnc/retardbnc.rb $ ruby retardbnc.rb irc.enterthegame.com Listening for client connections on 127.0.0.1:6667... [2008-04-30 16:40:02 Wed][127.0.0.1:46507][client_conn] accepted connection [2008-04-30 16:40:02 Wed][?.?.?.?:0][irc_conn] established connection [2008-04-30 16:40:09 Wed][127.0.0.1:46507][client_conn] unbind [2008-04-30 16:40:09 Wed][?.?.?.?:0][irc_conn] unbind On windows, the "?.?.?.?:0" will be a valid IP/port. I''ll try to whittle down that code to the simplest case that still exhibits the problem... Regards, Bill
Roger Pack
2008-Apr-30 20:27 UTC
[Eventmachine-talk] get_peername - start_server vs. connect
yeah after it calls ''connection established'' or what not then you should be able to get a peername. On Wed, Apr 30, 2008 at 5:47 PM, Bill Kelly <billk at cts.com> wrote:> > From: "Roger Pack" <rogerpack2005 at gmail.com> > > > > > > have the connections been successfully connected before you call peername? > > > > I presume so. I''m making the call from the post_init method. > > Strange. I tried to write a very minimal bit of code to reproduce > the problem and wasn''t able to. > > I do still see the problem in the following code, but only on > Linux, not on Windows: > > http://tastyspleen.net/~billk/ruby/retardbnc/retardbnc.rb > > $ ruby retardbnc.rb irc.enterthegame.com > Listening for client connections on 127.0.0.1:6667... > [2008-04-30 16:40:02 Wed][127.0.0.1:46507][client_conn] accepted connection > [2008-04-30 16:40:02 Wed][?.?.?.?:0][irc_conn] established connection > [2008-04-30 16:40:09 Wed][127.0.0.1:46507][client_conn] unbind > [2008-04-30 16:40:09 Wed][?.?.?.?:0][irc_conn] unbind > > > On windows, the "?.?.?.?:0" will be a valid IP/port. > > > I''ll try to whittle down that code to the simplest case that > still exhibits the problem... > > > > > Regards, > > Bill > > > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talk >
Bill Kelly
2008-Apr-30 21:57 UTC
[Eventmachine-talk] get_peername - start_server vs. connect
From: "Bill Kelly" <billk at cts.com>> > I''ll try to whittle down that code to the simplest case that > still exhibits the problem...OK... turns out the key is whether EventMachine::connect() is going to localhost, or connecting to a remote host. When connecting to a remote host, get_peername is not working for me on Linux: http://tastyspleen.net/~billk/ruby/test/em_get_peername3.rb On linux, I get: $ ruby em_get_peername3.rb RemoteClient initialize RemoteClient peer is ?.?.?.?:0 client2: connected to server callback On windows, I get: $ ruby em_get_peername3.rb RemoteClient initialize RemoteClient peer is 205.134.185.250:6667 client2: connected to server callback So... is this a bug? Or is get_peername not supposed to be used on connections established via connect() ? Regards, Bill
Roger Pack
2008-May-01 13:08 UTC
[Eventmachine-talk] get_peername - start_server vs. connect
inserting this code seems to yield slightly better results [not sure why] EM::add_periodic_timer(1) { @remote_port, @remote_ip = pn ? Socket.unpack_sockaddr_in(pn) : [0, "?.?.?.?"] peer_port, peer_host Socket.unpack_sockaddr_in(self.get_peername) if self.get_peername warn "#{self.class.name} peer is #@remote_ip:#@remote_port, #{peer_port}, #{peer_host}" } end On Wed, Apr 30, 2008 at 10:57 PM, Bill Kelly <billk at cts.com> wrote:> > From: "Bill Kelly" <billk at cts.com> > > > > > > I''ll try to whittle down that code to the simplest case that > > still exhibits the problem... > > > > OK... turns out the key is whether EventMachine::connect() is > going to localhost, or connecting to a remote host. When > connecting to a remote host, get_peername is not working for > me on Linux: > > http://tastyspleen.net/~billk/ruby/test/em_get_peername3.rb > > On linux, I get: > > $ ruby em_get_peername3.rb > RemoteClient initialize > RemoteClient peer is ?.?.?.?:0 > client2: connected to server callback > > On windows, I get: > > $ ruby em_get_peername3.rb > RemoteClient initialize > RemoteClient peer is 205.134.185.250:6667 > client2: connected to server callback > > > So... is this a bug? Or is get_peername not supposed to be > used on connections established via connect() ? > > > > > Regards, > > Bill > > > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talk >