Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #6523 > unrolled thread
| Started by | Merhawi Fissehaye <merhawifissehaye@gmail.com> |
|---|---|
| First post | 2012-04-28 03:45 -0700 |
| Last post | 2012-04-28 03:58 -0700 |
| Articles | 10 — 3 participants |
Back to article view | Back to comp.lang.ruby
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
| From | Merhawi Fissehaye <merhawifissehaye@gmail.com> |
|---|---|
| Date | 2012-04-28 03:45 -0700 |
| Subject | Ruby Socket Programming: No connection could be made error |
| Message-ID | <20233599.660.1335609938128.JavaMail.geo-discussion-forums@vbq19> |
I am a beginner and I wanted to see how network programs are written in Ruby and I tried a sample Ruby code I found on the internet. There are two programs server.rb running in the background and client.rb trying to connect to my server program at the port number specific to the server program.
I found the following error when running client.rb :
client.rb:6:in 'initialize' : No connection could be made because the target machine actively refused it. - connect(2) (Errno::ECONNREFUSED)
from client.rb:6:in 'open'
from client.rb:6:in '<main>'
I am running the program from DOS
[toc] | [next] | [standalone]
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Date | 2012-04-28 12:53 +0200 |
| Message-ID | <a020hfF4scU1@mid.individual.net> |
| In reply to | #6523 |
On 28.04.2012 12:45, Merhawi Fissehaye wrote: > I am a beginner and I wanted to see how network programs are written in Ruby and I tried a sample Ruby code I found on the internet. There are two programs server.rb running in the background and client.rb trying to connect to my server program at the port number specific to the server program. > I found the following error when running client.rb : > > client.rb:6:in 'initialize' : No connection could be made because the target machine actively refused it. - connect(2) (Errno::ECONNREFUSED) > from client.rb:6:in 'open' > from client.rb:6:in '<main>' Could be any number of reasons from that you have misconfigured ports or the server is listening on 127.0.0.1 only which cannot be connected from a different machine or firewall blocking access... Can you give more details, show the code? > I am running the program from DOS Are you serious about that? Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/
[toc] | [prev] | [next] | [standalone]
| From | Merhawi Fissehaye <merhawifissehaye@gmail.com> |
|---|---|
| Date | 2012-04-28 04:07 -0700 |
| Message-ID | <3871590.742.1335611230186.JavaMail.geo-discussion-forums@vbqq1> |
| In reply to | #6524 |
************* 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
[toc] | [prev] | [next] | [standalone]
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Date | 2012-04-28 15:35 +0200 |
| Message-ID | <a02a0aF87nU1@mid.individual.net> |
| In reply to | #6525 |
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/
[toc] | [prev] | [next] | [standalone]
| From | Merhawi Fissehaye <merhawifissehaye@gmail.com> |
|---|---|
| Date | 2012-04-28 06:41 -0700 |
| Message-ID | <13301714.803.1335620465957.JavaMail.geo-discussion-forums@vbli11> |
| In reply to | #6528 |
Are there any modules to be included or at least to be installed (...the gem install things )? Or is there any way of running my ruby programs from something other than the DOS command window?
[toc] | [prev] | [next] | [standalone]
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Date | 2012-04-28 20:30 +0200 |
| Message-ID | <a02r9iF6eaU1@mid.individual.net> |
| In reply to | #6529 |
On 28.04.2012 15:41, Merhawi Fissehaye wrote: > Are there any modules to be included or at least to be installed > (...the gem install things )? Or is there any way of running my ruby > programs from something other than the DOS command window? Command window is perfectly OK. I was just wondering about your operating system. I haven't heard someone use DOS in a while. :-) Now, what's with your connection issue? Does it work now? Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/
[toc] | [prev] | [next] | [standalone]
| From | Simon Krahnke <overlord@gmx.li> |
|---|---|
| Date | 2012-04-28 21:59 +0200 |
| Message-ID | <87wr4z631b.fsf@xts.gnuu.de> |
| In reply to | #6530 |
* Robert Klemme <shortcutter@googlemail.com> (20:30) schrieb: >On 28.04.2012 15:41, Merhawi Fissehaye wrote: >> Are there any modules to be included or at least to be installed >> (...the gem install things )? Or is there any way of running my ruby >> programs from something other than the DOS command window? > > Command window is perfectly OK. I was just wondering about your > operating system. I haven't heard someone use DOS in a while. :-) Also you probably need two command windows, one to start the server in, and the other to start the client in while the server is still running. mfg, simon .... l
[toc] | [prev] | [next] | [standalone]
| From | Merhawi Fissehaye <merhawifissehaye@gmail.com> |
|---|---|
| Date | 2012-05-02 07:31 -0700 |
| Message-ID | <33022149.966.1335969115444.JavaMail.geo-discussion-forums@pbcgj9> |
| In reply to | #6530 |
In DOS I meant that I launched command prompt with ruby and tried to run ruby filename from there. Well it has worked for me very well in Ubuntu.
[toc] | [prev] | [next] | [standalone]
| From | Simon Krahnke <overlord@gmx.li> |
|---|---|
| Date | 2012-05-03 17:19 +0200 |
| Message-ID | <87obq55m3d.fsf@xts.gnuu.de> |
| In reply to | #6534 |
* Merhawi Fissehaye <merhawifissehaye@gmail.com> (2012-05-02) schrieb: > In DOS I meant that I launched command prompt with ruby and tried to > run ruby filename from there. Well it has worked for me very well in > Ubuntu. The usage of DOS as a description of a Windows-NT command prompt would be wrong, but of a Linux shell that is totally inappropriate. mfg, simon .... l
[toc] | [prev] | [next] | [standalone]
| From | Merhawi Fissehaye <merhawifissehaye@gmail.com> |
|---|---|
| Date | 2012-04-28 03:58 -0700 |
| Message-ID | <12305705.735.1335610739994.JavaMail.geo-discussion-forums@vbqq1> |
| In reply to | #6523 |
************** 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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.ruby
csiph-web