Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #6528

Re: Ruby Socket Programming: No connection could be made error

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.ruby
Subject Re: Ruby Socket Programming: No connection could be made error
Date 2012-04-28 15:35 +0200
Message-ID <a02a0aF87nU1@mid.individual.net> (permalink)
References <20233599.660.1335609938128.JavaMail.geo-discussion-forums@vbq19> <a020hfF4scU1@mid.individual.net> <3871590.742.1335611230186.JavaMail.geo-discussion-forums@vbqq1>

Show all headers | View raw


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/

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Ruby Socket Programming: No connection could be made error Merhawi Fissehaye <merhawifissehaye@gmail.com> - 2012-04-28 03:45 -0700
  Re: Ruby Socket Programming: No connection could be made error Robert Klemme <shortcutter@googlemail.com> - 2012-04-28 12:53 +0200
    Re: Ruby Socket Programming: No connection could be made error Merhawi Fissehaye <merhawifissehaye@gmail.com> - 2012-04-28 04:07 -0700
      Re: Ruby Socket Programming: No connection could be made error Robert Klemme <shortcutter@googlemail.com> - 2012-04-28 15:35 +0200
        Re: Ruby Socket Programming: No connection could be made error Merhawi Fissehaye <merhawifissehaye@gmail.com> - 2012-04-28 06:41 -0700
          Re: Ruby Socket Programming: No connection could be made error Robert Klemme <shortcutter@googlemail.com> - 2012-04-28 20:30 +0200
            Re: Ruby Socket Programming: No connection could be made error Simon Krahnke <overlord@gmx.li> - 2012-04-28 21:59 +0200
            Re: Ruby Socket Programming: No connection could be made error Merhawi Fissehaye <merhawifissehaye@gmail.com> - 2012-05-02 07:31 -0700
              Re: Ruby Socket Programming: No connection could be made error Simon Krahnke <overlord@gmx.li> - 2012-05-03 17:19 +0200
  Re: Ruby Socket Programming: No connection could be made error Merhawi Fissehaye <merhawifissehaye@gmail.com> - 2012-04-28 03:58 -0700

csiph-web