From: Daniel Flores on 27 Jul 2010 17:46 hello i was learning about ruby and on the book i am reading it shows the part where i can create a chatserver with Gserver well lookingon the internet shows the server code everywhere. but when i am trying to do a chat client it always failed on me. i wouldl ike that it works like a conection with telnet or with netcat. here is the failling code: require 'socket' # Sockets are in standard library host = 'localhost' port = 1234 while line = s.gets # Read lines from the socket puts line # And print with platform line terminator s.puts gets end s.puts "Connection close!!" s.close THANK YOU in advance -- Posted via http://www.ruby-forum.com/.
From: Fabian Marin on 27 Jul 2010 22:07 Daniel, you need to include more info. What errors are you getting? -- Posted via http://www.ruby-forum.com/.
From: Jesús Gabriel y Galán on 28 Jul 2010 05:05 On Tue, Jul 27, 2010 at 11:46 PM, Daniel Flores <soloparamsn2(a)hotmail.com> wrote: > hello i was learning about ruby and on the book i am reading it shows > the part where i can create a chatserver with Gserver > > well lookingon the internet shows the server code everywhere. > > but when i am trying to do a chat client it always failed on me. > i wouldl ike that it works like a conection with telnet or with netcat. > > here is the failling code: > > require 'socket' # Sockets are in standard library > > host = 'localhost' > port = 1234 > > while line = s.gets # Read lines from the socket > puts line # And print with platform line terminator > s.puts gets > end > s.puts "Connection close!!" > s.close For me this code fails with this error: test_socket.rb:6: undefined local variable or method `s' for main:Object (NameError) obviously, because you haven't assign anything to s. Do you have a different version of your program, and what are the errors you are getting? Jesus.
From: Daniel Flores on 28 Jul 2010 20:10 Fabian Marin wrote: > Daniel, you need to include more info. > > What errors are you getting? I am sorry!!! here is the failling code: require 'socket' # Sockets are in standard library host = 'localhost' port = 1234 s = TCPSocket.open(host, port) while line = s.gets # Read lines from the socket puts line # And print with platform line terminator s.puts gets end s.puts "Connection close!!" s.close Well i guess it works now, but there is a problem the code becuase the cliente waits for the server to reply in order to place more data and the other way around. There is a way to be waiting both I/O and react depending on which was activated with data? I saw that Select might be an alternative but i havent found an example that guide me through the SELECT options. Thank you in advance! -- Posted via http://www.ruby-forum.com/.
|
Pages: 1 Prev: Which Ruby is in use? Next: tool to compare DB schema against DDL file |