Path: csiph.com!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.ruby Subject: Re: Ruby Socket Programming: No connection could be made error Date: Sat, 28 Apr 2012 15:35:01 +0200 Lines: 37 Message-ID: References: <20233599.660.1335609938128.JavaMail.geo-discussion-forums@vbq19> <3871590.742.1335611230186.JavaMail.geo-discussion-forums@vbqq1> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net uvkmy4ATjM9kalOnKLgafwXJvUzGeHrl2lKzTln2ZJjfiCAqY= Cancel-Lock: sha1:eCX6mRVLSMNY/nstuiXzmGEsWfw= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:12.0) Gecko/20120420 Thunderbird/12.0 In-Reply-To: <3871590.742.1335611230186.JavaMail.geo-discussion-forums@vbqq1> Xref: csiph.com comp.lang.ruby:6528 On 28.04.2012 13:07, Merhawi Fissehaye wrote: > ************* Here is client.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 be glad to hear recommendations pls Works like a charm for me. Did you maybe start the client before the server? Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/