init.rb in rwddemo-0.8 vs init.rb in rwddemo-0.90

- old
+ new

@@ -226,8 +226,44 @@ fileB=File.open(RWDFile,"w") #deletes and opens a the file in fileName fileB.write($tempdoc) #writes the contents of doc into the file fileB.close - + require 'socket' # Network stuff + host = "127.0.0.1" + port = $port + + # Create a socket to listen on and bind it to the host and port + freeportfound = false + until freeportfound + begin + @socket = UDPSocket::new() + @socket.bind(host, port) + freeportfound = true +$port = port + # Rescue the "Address in use" error + rescue Errno::EADDRINUSE + puts "RWD Startup: Port #{port} on host #{host} is already in use." + port=port +1 + puts "trying port: #{port}" + # Rescue the "Address not available' error + rescue Errno::EADDRNOTAVAIL + puts "RWD Startup: Address #{host} is not available to bind." + port =port + 1 + puts "trying port: #{port}" + # Rescue "permission denied errors + rescue Errno::EACCES + puts "RWD Startup: Access denied when binding interface addresses. ?" + port =port + 1 + puts "trying port: #{port}" + # Rescue all other errors + rescue + puts "RWD Startup: An error occured." + port =port + 1 + puts "trying port: #{port}" + # Rescue all other errors + end -RwdTinker.file(RWDFile).serve($port) # start the main class and program +end + + +RwdTinker.file(RWDFile).serve(port) # start the main class and program