dkondr (dkondr) wrote in ruby_lang,

XP: "An existing connection was forcibly closed" ECONNRESET

(cross-posted from
I am running Ruby 1-185-21 on Win XP without any proxy enabled.
When trying to connect to HTTP server (both server and client are my Ruby scripts) at *localhost* I get this error:
c:/usr/ruby/lib/ruby/1.8/net/protocol.rb:133:in `sysread': An existing connection was forcibly closed by the remote host. (Errno::ECONNRESET)

Interesting facts:
1) Firefox works without any problems with my Ruby server!!!
2) IE doesn't work with my Ruby server!!!
3) My client works fine with all other HTTP servers on the Internet, except for my Ruby server on localhost :(

(see bellow complete trace of this error and source of my simple server and client)

Any ideas?
=== localhost error trace: 

ruby test-serv.rb localhost 10001
[Sat Sep 23 01:22:16 2006] TimeServer start
Server started...
Connecting to server localhost:10001 at Sat Sep 23 01:22:21 +0400 2006
[Sat Sep 23 01:22:21 2006] TimeServer client:1203 localhost<> connect
[Sat Sep 23 01:22:21 2006] TimeServer client:1203 disconnect
[Sat Sep 23 01:22:21 2006] TimeServer stop
c:/usr/ruby/lib/ruby/1.8/net/protocol.rb:133:in `sysread': An existing connection was forcibly closed by the remote host. (Errno::ECONNRESET)
        from c:/usr/ruby/lib/ruby/1.8/net/protocol.rb:133:in `rbuf_fill'
        from c:/usr/ruby/lib/ruby/1.8/timeout.rb:56:in `timeout'
        from c:/usr/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout'
        from c:/usr/ruby/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill'
        from c:/usr/ruby/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
        from c:/usr/ruby/lib/ruby/1.8/net/protocol.rb:126:in `readline'
        from c:/usr/ruby/lib/ruby/1.8/net/http.rb:2017:in `read_status_line'
        from c:/usr/ruby/lib/ruby/1.8/net/http.rb:2006:in `read_new'
        from c:/usr/ruby/lib/ruby/1.8/net/http.rb:1047:in `request'
        from c:/usr/ruby/lib/ruby/1.8/net/http.rb:1034:in `request'
        from c:/usr/ruby/lib/ruby/1.8/net/http.rb:543:in `start'
        from c:/usr/ruby/lib/ruby/1.8/net/http.rb:1032:in `request'
        from c:/usr/ruby/lib/ruby/1.8/net/http.rb:769:in `get'
        from test-serv.rb:35

=== no error trace: 

C:\wks\ruby-wks>ruby test-serv.rb 80
Connecting to server at Sat Sep 23 01:29:28 +0400 2006
Code: 200 Msg: OK
Connecting to server at Sat Sep 23 01:29:34 +0400 2006
Code: 200 Msg: OK

=== source:
require 'gserver'
require 'net/http'

  TIME_OUT  = 5
  host      = ARGV[0] 
  port      = ARGV[1]
  if host == 'localhost' then
  # A server that returns the time in seconds since 1970.
    class TimeServer < GServer
      def initialize(port=10001, *args)
        super(port, *args)
      def serve(io)
    # Run the server with logging enabled (it's a separate thread).
    server =
    server.audit = true                  # Turn logging on.
    puts "Server started...\n"
  end #host == 'localhost'

  # Test server
  while (true)
    sleep TIME_OUT
    puts("Connecting to server #{host}:#{port} at #{}\n")  
    h =,port)
    res, data = h.get('/index.html', nil )
    puts("Code: #{res.code} Msg: #{res.message}\n")

  • Post a new comment


    default userpic
Drop the shit, use Python. Ne tiani vsiakuju drian' v rot, Dima.
With all respect to Python, I can't go allong with the way it forces me to format source code.

Ruby is more natural in many aspects.

Kon’nichi wa, Ruby!
It forces you to format your code no more than this disgusting requirement of Ruby to use end, or no less ridiculous insistence of many other languages to apply braces. I have at my bookshelf a preprint of famous Sh. Guberman - "Project Libral, liberal programming language", but practical programming languages (un)fortunately do not fly so high, they still need some means of expressing their constructs and re-using already existent indentation is not the dumbest idea. This idea aligns well with true Hungarian notation - it liberates you from making arbitrary choices and allow to concentrate on essential.
Ok, ok...
After all what matters most is how easily one can accomplish the task at hand with one language or another. When we talk 'language' in fact we talk many other things as well, such as good libraries and tools. (I am extremly lazy programmer :)
So I will drop Ruby and switch to Python in case it will allow me to do fast and easy the following:
1) lightweight REST-full protocol between WEB peers. In other words I need embedable WEB server that will allow sevral apps exchange messages using simple protocol on top of HTTP (get & post + params).
2) process controll (start, stop) and IPC. Any form of IPC (such as messaging or tuple space, etc) to make communication between local and distributed processes (includiing Win32 processes!) possible.

Also, what are other reasons you don't like Ruby so much?
It is not the most appropriate place to admit why I don't like Ruby, is it? ;-) Basically, my initial acquaintance with dynamically typed languages started in 1998 and that was Python. I can not say I did not know or did not try this before, but it was Python with which I experienced that nothing stays between me and computer in expressing my ideas. It is probably personal, but I found ideal toolset, and I suddenly realized that it was not me too picky or to dumb to not master MFC, say, but when compared with Tk, especially it modern Tkinter Python bidnings it is just silly to spend your time with inferior tools, when perfect toolset is there. And it still holds about almost everything - GUI, network programming, modelling of complex algorithmic stuff (Python a bit slow to run computationally extensive stuff, but to model in Python and recode parts in C/C++ is much faster), IPC - whatever.

Ruby on one hand is too similar to Python - they are actually converging, stealing features from each other, on the other hand it is too eclectic, not many rationale for some things, too many borrowing of dubious ideas from Perl. Libraries are much more extensive still for Python, all this networking, XML processing, numeric stuff etc. is piece of cake thanks to them.

Start/stop of processes is not so easy, especially if you want cross platform code, but this is not because of Python, but because processing models are pretty different for Windows and UNIX. I participated in writing job dispatcher (in Python ;-) for computer cluster, I faced with this. IPC through TCP is easy. REST - you better don't bother with HTTP/XML stuff, it is simple enough to use sockets.

Btw, in simple words, what's so cool about REST? Am I missing something?
Dragon is the official source of information regarding all aspects of the Dungeons & Dragons hobby and provides D&D players with the tools, utilities, and excitement they need to raise the level of their play experience.
I haven't run any tests, but I can give you my intuition. My intuition is that by using GServer, you're not actually implementing a correct HTTP server. In particular, I'm not sure your server actually reads from the io object anywhere. That could cause problems for an HTTP client that expects to have its output eaten by something. Firefox & other clients may be more accepting about strange behavior like that. In any case, try reading from the io object, or subclassing a real HTTP server (which will read the HTTP request), or something similar to that. No promises that this will work, but it sounds like the problem to me.
Good, I'm glad someone more knowledgeable than I was able to help. Enjoy your project!