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
On Tue, Jul 27, 2010 at 11:46 PM, Daniel Flores
[email protected] wrote:
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.
Daniel, you need to include more info.
What errors are you getting?
Fabian M. 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!
sorry about necro posting, but just saw this thread ^.^’
and thought I’d post a possible answer, tho im sure you found this out
by now but to help anyone else who happens by it like I did…
not sure ur OS but ive read that in windows ‘gets’ seems to block the
code. So you’d have to find an alternate I/O. You could try threading
‘gets’ tho, Im having trouble with threads myself and cant be too much
help with it lol
On Tuesday, July 27, 2010 5:46 PM Daniel Flores wrote:
require ‘socket’ # Sockets are in standard library
THANK YOU in advance
Posted via http://www.ruby-forum.com/.
On Tuesday, July 27, 2010 10:07 PM Fabian M. wrote:
Daniel, you need to include more info.
What errors are you getting?
–
Posted via http://www.ruby-forum.com/.
On Wednesday, July 28, 2010 5:05 AM Jes?s_Gabriel_y_Gal?n wrote:
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 have not assign anything to s. Do you have a
different version of your program, and what are the errors you are
getting?
Jesus.
On Wednesday, July 28, 2010 8:10 PM Daniel Flores wrote:
cliente waits for the server to reply in order to place more data and
Posted via http://www.ruby-forum.com/.