hi, i am a beginner in ruby and
i've made to tiny scripts but it doesn't seem to work if you have any idea
thanks :
server :
require 'gserver'
class BasicServer < GServer
def serve(io)
loop do
line = ""
line = io.gets
puts line
io.puts("Hello world! "+line )
end
end
end
server = BasicServer.new(1234)
server.start
server.join
Client :
require "socket"
print("Connexion...")
clientsock = TCPsocket.open("localhost", 1234)
print(" terminée\n")
clientsock.write("toto")
puts(clientsock.gets)
clientsock.close
regards
Bussiere
hi, i am a beginner in ruby and
i've made to tiny scripts but it doesn't seem to work if you have any idea
thanks :
server :
require 'gserver'
class BasicServer < GServer
def serve(io)
loop do
line = ""
line = io.gets
puts line
io.puts("Hello world! "+line )
end
end
end
server = BasicServer.new(1234)
server.start
server.join
Client :
require "socket"
print("Connexion...")
clientsock = TCPsocket.open("localhost", 1234)
print(" terminée\n")
clientsock.write("toto")
The problem is that in the server you are doing a io.gets, so it's
waiting for a \n, which write doesn't produce. Try this:
clientsock.puts("toto")
puts(clientsock.gets)
clientsock.close
Jesus.
···
On Thu, May 6, 2010 at 10:26 PM, bussiere bussiere <bussiereruby@gmail.com> wrote:
it works
thanks a lot
Bussiere
···
2010/5/6 Jesús Gabriel y Galán <jgabrielygalan@gmail.com>
On Thu, May 6, 2010 at 10:26 PM, bussiere bussiere > <bussiereruby@gmail.com> wrote:
> hi, i am a beginner in ruby and
> i've made to tiny scripts but it doesn't seem to work if you have any
idea
> thanks :
> server :
> require 'gserver'
>
> class BasicServer < GServer
> def serve(io)
> loop do
> line = ""
> line = io.gets
> puts line
> io.puts("Hello world! "+line )
> end
> end
> end
>
> server = BasicServer.new(1234)
> server.start
> server.join
>
> Client :
> require "socket"
> print("Connexion...")
> clientsock = TCPsocket.open("localhost", 1234)
> print(" terminée\n")
> clientsock.write("toto")
The problem is that in the server you are doing a io.gets, so it's
waiting for a \n, which write doesn't produce. Try this:
clientsock.puts("toto")
> puts(clientsock.gets)
> clientsock.close
Jesus.