Hello Team,
I need your help with sockets.
I read the PickAxe information on Socket on Apendix A. I also read an
article “Sockets programming in Ruby” By: M. Tim Jones. All the examples
provided worked within their context.
However, I am new to Socket programming and to Ruby but I am trying to
establish a simple connection between a TCPServer and a client.
Basically, I would like the server side to start and block itself
waiting
for a request from a client.
The client will connect and request a service such as execute a command
on
the servers side and return the output.
I am having heck of a time trying to get a simple sample program to
work.
The connection is actually established, but I don’t see the string that
I
sent the server and I don’t get anything back on the client either.
Here is my “server”, please don’t laugh!
require ‘socket’
port = 19557
server = TCPServer.new(‘localhost’, port)
while (session = server.accept)
puts “Inside while…”
puts session.to_s
session.close
end
This is suppose to be the client:
require ‘socket’
streamSock = TCPSocket.new( ‘localhost’, 19557 )
streamSock.send( “Hello\n” )
str = streamSock.recv( 100 )
print str
streamSock.close
I am willing to read any documentation recommended.
Thank you