code/superant.com.rwdtinkerbackwindow/controlclient.rb in rwdshell-0.98 vs code/superant.com.rwdtinkerbackwindow/controlclient.rb in rwdshell-0.99

- old
+ new

@@ -1,99 +1,96 @@ # Bind message passing socket to rwdtinker application - def runcontrolcommand -require 'socket' + require 'socket' -# Change this line... - ip = '127.0.0.1' -# And this one... - port = $rwdcontrolport1 - if @a_remoteportinput - port = @a_remoteportinput.to_i - end + # Change this line... + ip = '127.0.0.1' + # And this one... + port = $rwdcontrolport1 + if @a_remoteportinput + port = @a_remoteportinput.to_i + end - commandtext = @a_remotecommandinput.to_s - remotehostnotfound = true - if (commandtext == "stop") - begin - client = UDPSocket::new() - client.send(commandtext, 0, ip, port) - @socket = UDPSocket::new() - @socket.bind(ip, port) - # Rescue the "Address in use" error - rescue Errno::EADDRINUSE - - databack, info = client.recv(128) - @remotecommandresult = databack - @lastremotecommand = "rwdtinker remote:: Port #{port} on host #{ip} ." - remotehostnotfound = false - - # Rescue the "Address not available" error - rescue Errno::EADDRNOTAVAIL - puts "Network plugin: Address #{host} is not available to bind." + commandtext = @a_remotecommandinput.to_s + remotehostnotfound = true + if (commandtext == "stop") + begin + client = UDPSocket::new() + client.send(commandtext, 0, ip, port) + @socket = UDPSocket::new() + @socket.bind(ip, port) + # Rescue the "Address in use" error + rescue Errno::EADDRINUSE - # Rescue "permission denied errors - rescue Errno::EACCES - puts "Network plugin: Access denied when binding interface addresses. Did you try to bind a port under 1024 as a regular user?" + databack, info = client.recv(128) + @remotecommandresult = databack + @lastremotecommand = "rwdtinker remote:: Port #{port} on host #{ip} ." + remotehostnotfound = false -# Rescue all other errors - rescue - puts "Network plugin: An error occured." - - # Rescue all other errors - end - if remotehostnotfound - @remotecommandresult = "Remote Host not running" - end - @socket.close - # Close the socket after use - client.close() - end + # Rescue the "Address not available" error + rescue Errno::EADDRNOTAVAIL + puts "Network plugin: Address #{host} is not available to bind." - remotehostnotfound = true - if (commandtext == "query") - begin - client = UDPSocket::new() - client.send(commandtext, 0, ip, port) - @socket = UDPSocket::new() - @socket.bind(ip, port) - # Rescue the "Address in use" error - rescue Errno::EADDRINUSE - - databack, info = client.recv(128) - @remotecommandresult = databack - @lastremotecommand = "rwdtinker remote: Port #{port} on host #{ip} " - remotehostnotfound = false - - # Rescue the "Address not available' error - rescue Errno::EADDRNOTAVAIL - puts "Network plugin: Address #{host} is not available to bind." - - # Rescue "permission denied errors - rescue Errno::EACCES - puts "Network plugin: Access denied when binding interface addresses. Did you try to bind a port under 1024 as a regular user?" - - # Rescue all other errors - rescue - puts "Network plugin: An error occured." - - # Rescue all other errors - end -@socket.close + # Rescue "permission denied errors + rescue Errno::EACCES + puts "Network plugin: Access denied when binding interface addresses. Did you try to bind a port under 1024 as a regular user?" -# Close the socket after use -client.close() -end + # Rescue all other errors + rescue + puts "Network plugin: An error occured." - if remotehostnotfound - @remotecommandresult = "Remote Host not running" - end + # Rescue all other errors + end + if remotehostnotfound + @remotecommandresult = "Remote Host not running" + end + @socket.close + # Close the socket after use + client.close() + end + + remotehostnotfound = true + if (commandtext == "query") + begin + client = UDPSocket::new() + client.send(commandtext, 0, ip, port) + @socket = UDPSocket::new() + @socket.bind(ip, port) + # Rescue the "Address in use" error + rescue Errno::EADDRINUSE + + databack, info = client.recv(128) + @remotecommandresult = databack + @lastremotecommand = "rwdtinker remote: Port #{port} on host #{ip} " + remotehostnotfound = false + + # Rescue the "Address not available' error + rescue Errno::EADDRNOTAVAIL + puts "Network plugin: Address #{host} is not available to bind." + + # Rescue "permission denied errors + rescue Errno::EACCES + puts "Network plugin: Access denied when binding interface addresses. Did you try to bind a port under 1024 as a regular user?" + + # Rescue all other errors + rescue + puts "Network plugin: An error occured." + + # Rescue all other errors + end + @socket.close + + # Close the socket after use + client.close() + end + + if remotehostnotfound + @remotecommandresult = "Remote Host not running" + end end # list the remote control options on the screen def showremoteportoptions - - @remoteportoptions = $rwdcontrolports.rwd_options - @remotecommandoptions = ["query","stop"].rwd_options - end - - + + @remoteportoptions = $rwdcontrolports.rwd_options + @remotecommandoptions = ["query","stop"].rwd_options +end