B
Bigmac Turdsplash
server/client connection
so, im only a few days into ruby, im working on some tcp and there is a
problem with my client.rb... if str == ???? this if statement is always
skipped and im not sure why?
also, from the server with the gets command i want to send the client a
string like "mike skateboard boxing" then when the client recives this
string how can i brake this into 3 arrays or strings?
#server.rb
require "socket"
dts = TCPServer.new('localhost', 1234)
loop do
Thread.start(dts.accept) do |s|
print(s, " is accepted\n")
#gets, what command to send to the client?
str = gets
s.write(str)
print(s, " is gone\n")
s.close
end
end
------------end of server-------------
#client.rb
require 'socket'
while true
streamSock = TCPSocket.new( "127.0.0.1", 1234 )
str = streamSock.recv( 100 )
print str
if str == 'mike'
print 'Hi mike'
elsif str == 'user'
print 'hi user'
end
end
--------end of client
so, im only a few days into ruby, im working on some tcp and there is a
problem with my client.rb... if str == ???? this if statement is always
skipped and im not sure why?
also, from the server with the gets command i want to send the client a
string like "mike skateboard boxing" then when the client recives this
string how can i brake this into 3 arrays or strings?
#server.rb
require "socket"
dts = TCPServer.new('localhost', 1234)
loop do
Thread.start(dts.accept) do |s|
print(s, " is accepted\n")
#gets, what command to send to the client?
str = gets
s.write(str)
print(s, " is gone\n")
s.close
end
end
------------end of server-------------
#client.rb
require 'socket'
while true
streamSock = TCPSocket.new( "127.0.0.1", 1234 )
str = streamSock.recv( 100 )
print str
if str == 'mike'
print 'Hi mike'
elsif str == 'user'
print 'hi user'
end
end
--------end of client