Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Merhawi Fissehaye Newsgroups: comp.lang.ruby Subject: Re: Ruby Socket Programming: No connection could be made error Date: Sat, 28 Apr 2012 03:58:59 -0700 (PDT) Organization: http://groups.google.com Lines: 25 Message-ID: <12305705.735.1335610739994.JavaMail.geo-discussion-forums@vbqq1> References: <20233599.660.1335609938128.JavaMail.geo-discussion-forums@vbq19> NNTP-Posting-Host: 213.55.108.10 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1335611533 19404 127.0.0.1 (28 Apr 2012 11:12:13 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 28 Apr 2012 11:12:13 +0000 (UTC) In-Reply-To: <20233599.660.1335609938128.JavaMail.geo-discussion-forums@vbq19> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=213.55.108.10; posting-account=r6mg2QoAAACxjo6Dyd1jXBLTBBquIGER User-Agent: G2/1.0 Xref: csiph.com comp.lang.ruby:6526 ************** Here is clients.rb require 'socket' hostname = 'localhost' port = 2000 s = TCPSocket.open( hostname, port ) while line = s.gets # Read lines from the socket puts line.chop # And print with platform line terminator end s.close # Close the socket when done ************ Here is server.rb require 'socket' # Get socket from stdlib server = TCPServer.open( 2000 ) # Socket to listen port 2000 loop { # Servers run forever client = server.accept # Wait for a client to connect client.puts( Time.now.ctime ) # Send the time to the client client.puts "Closing the connection. Bye!" client.close # Disconnect from the client } I am just beginning to write socket programs! I would love to hear any recommendations pls.