Socket probleme

Hey guys !
i want to create a server that close when client send END_CALL
so i writed this code
Server.rb
require "socket"

s = TCPServer.new("127.0.0.1",2000)
msg = ""
client = s.accept()
while msg = client.gets
  puts msg
  if msg.equal?("END") == true
    break
  end
end
client.close()
s.close()

Client.rb
require "socket"

s = TCPServer.new("127.0.0.1",2000)
msg = ""
client = s.accept()
while msg = client.gets
  puts msg
  if msg.equal?("END") == true
    break
  end
end
client.close()
s.close()

but when i type END_CALL in the client nothing happen
pliz help and thanks

···

--
Posted via http://www.ruby-forum.com/.

Hey guys !
i want to create a server that close when client send END_CALL
so i writed this code
Server.rb
require "socket"

s = TCPServer.new("127.0.0.1",2000)
msg = ""
client = s.accept()
while msg = client.gets
   puts msg
   if msg.equal?("END") == true
     break
   end
end
client.close()
s.close()

Client.rb
require "socket"

s = TCPServer.new("127.0.0.1",2000)
msg = ""
client = s.accept()
while msg = client.gets
   puts msg
   if msg.equal?("END") == true
     break
   end
end
client.close()
s.close()

but when i type END_CALL in the client nothing happen
pliz help and thanks

It looks like you pasted the server code twice.

One problem is that you are testing for the string "END", but in reality the string is probably something else (hard to say what).

To find out, use

   p msg

instead of

   puts msg

and you will see if there is (for example) a newline in the string: "END\n", or if it is "END_CALL\n" or something else.

Also, you should replace

   if msg.equal?("END") == true

with

   if msg == "END"

Observe this in irb:

>> "a".equal? "a"
=> false

···

On 07/01/2013 03:06 PM, xcoder Blue_fox wrote:

Thanks dude , yes i pasted server code twice ^^
your solution worked for me !

···

--
Posted via http://www.ruby-forum.com/.