Hello Team,
In an attempt to learn about TCP Socket programming, I wrote the following
mini tiny ruby pgms.
Although they kind of work, I am having some problems. Here they are:
This is under AIX 5.3.
ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [powerpc-aix5.3.0.0]
1 - I start the server side first.
2 - Start client side.
3 - The client gets the msg session.write("Communication Established!!!").
4 - The server just "sits" there, when I expect the output of the date
command on the server console.
5 - If kill the client side, the server now executes the date command and
the actual output is displayed.
6 - The client side never gets the last msg from the server side.
7 - I kill the server side.
Your help will be appreciated.
SERVER SIDE
require 'socket'
port = 19557
server = TCPServer.new("", port)
while (session = server.accept)
session.write("Communication Established!!!")
input = session.gets
system("#{input}")
session.write("Request Received From Client:#{input}")
session.close
end
CLIENT SIDE
require 'socket'
streamSock = TCPSocket.new( 'nycserv-deva-app1nim', 19557 )
streamSock.send( "date\n", 1937 )
str = streamSock.recv( 100 )
print str
puts "\n"
str = streamSock.recv( 100 )
print str
puts "\n"
streamSock.close
ACTUAL RUN:
Server:
root@app1nim:/u/victor/executables/ruby>ruby ts5 (Here it just waits)
Client:
root@app2nim # ruby tc5
Communication Established!!!
NOW I KILL THE CLIENT SINCE NOTHING IS GOING ON ON THE SERVER:
tc5:8:in `recv': Interrupt
from tc5:8
===> /u/victor/executables/ruby
root@app2nim #
NOW THE SERVER DISPLAY THESE MSGS:
ts5:10: warning: Insecure world writable dir /usr/local in PATH, mode
0240777
Thu Sep 20 13:18:56 EDT 2007
Thank you
Victor