I am trying to interface to an API. I am instructed to use the server and port information provided to setup a TCP socket. I did that like this: require ''socket'' my_socket=TCPSocket::open("ip","port") Where "ip" and "port" are the provided ip and port of the server respectively. I am told that once the connection is established I will receive a greeting from the server. I was expecting to find that greeting in my_socket. Instead the contents of my_socket looks like this: #<TCPSocket:0x9961c80> Can anyone please tell me what I am doing wrong and what I need to do to get at the greeting? Obviously I am very green at this. Thanks for any input. ... doug -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Jun 11, 2010 at 3:04 AM, doug <ddjolley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am trying to interface to an API. I am instructed to use the server > and port information provided to setup a TCP socket. I did that like > this: > > require ''socket'' > my_socket=TCPSocket::open("ip","port") > > Where "ip" and "port" are the provided ip and port of the server > respectively. > > I am told that once the connection is established I will receive a > greeting from the server. I was expecting to find that greeting in > my_socket. Instead the contents of my_socket looks like this: > > #<TCPSocket:0x9961c80> > > Can anyone please tell me what I am doing wrong and what I need to do > to get at the greeting? Obviously I am very green at this. Thanks > for any input. >You have to read from your socket. Can you post some more of the code? It looks like you''re doing puts my_socket there. -- Leonardo Mateo. There''s no place like ~ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> You have to read from your socket.Ahh! I get it. (I said that I was green at this.) I now have it working except that it is REALLY slow.> Can you post some more of the code?Here is my code that is now working: require ''socket'' socket=TCPSocket::open("ip","port") out=File.open(''/tmp/debug1'',''w'') while line=socket.gets out.puts(line.chop) end socket.close out.close Do you have any idea why this would be very slow? Thanks. ... doug -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Jun 11, 2010 at 12:00 PM, doug <ddjolley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:>> You have to read from your socket. > > Ahh! I get it. (I said that I was green at this.) I now have it > working except that it is REALLY slow. > >> Can you post some more of the code? > > Here is my code that is now working: > > require ''socket'' > socket=TCPSocket::open("ip","port") > out=File.open(''/tmp/debug1'',''w'') > while line=socket.gets > out.puts(line.chop) > end > socket.close > out.close > > Do you have any idea why this would be very slow? Thanks. >It''s hard to say with no information, but it can be a slow connection. I know there''s a way to get the data asynchronously. I''ve even used it but a while ago, I should take a look at that code to point it to you, but this will avoid the while loop. -- Leonardo Mateo. There''s no place like ~ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Jun 11, 2010 at 2:15 PM, Leonardo Mateo <leonardomateo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Fri, Jun 11, 2010 at 12:00 PM, doug <ddjolley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> You have to read from your socket. >> >> Ahh! I get it. (I said that I was green at this.) I now have it >> working except that it is REALLY slow. >> >>> Can you post some more of the code? >> >> Here is my code that is now working: >> >> require ''socket'' >> socket=TCPSocket::open("ip","port") >> out=File.open(''/tmp/debug1'',''w'') >> while line=socket.gets >> out.puts(line.chop) >> end >> socket.close >> out.close >> >> Do you have any idea why this would be very slow? Thanks. >> > It''s hard to say with no information, but it can be a slow connection. > I know there''s a way to get the data asynchronously. I''ve even used it > but a while ago, I should take a look at that code to point it to you, > but this will avoid the while loop. >You can check the code on one of my github repositories. It is an unfinished project but that part works. http://github.com/kandalf/fluxy/blob/master/lib/fluxy_receiver.rb Take a look at the run method there. That''s for a server socket but might help you otu with this. Hope it helps. -- Leonardo Mateo. There''s no place like ~ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I think that I have the speed issue resolved. It appears to be an anomaly that is associated only with their sandbox server. The live server seems to work just fine. I can live with that. Thanks for your help. ... doug -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.