From: Chris Lervag Date: 2011-10-28T17:11:01+09:00 Subject: How to write TCPServer code that can exit? Hi all I've got a bit of a problem with my network code. Perhaps someone can help me out with this: I've got a program in which I run a TCP server. The code is basically like this: def start_server s = TCPServer.new(@port) loop do Thread.start(s.accept) do |session| # handle incoming connections... end end end The server code works just fine. However, my problem is that as it is, Im having trouble testing it. Once the server is initiated, I can't shut it down in code. Thus Im not able to figure out how to do rspec examples with it. If I try to start the server code in an rspec example and run some client stuff to test it, I never get to the next examples, because the server code wont quit. It just runs forever. Is there a better way to do this, so I can shut it down at will, and be able to make a proper test suite? Best regards, Chris -- Posted via http://www.ruby-forum.com/.