code/superant.com.rwdtinkerbackwindow/controlclient.rb in rwdshell-0.95 vs code/superant.com.rwdtinkerbackwindow/controlclient.rb in rwdshell-0.96

- old
+ new

@@ -1,30 +1,24 @@ -# +# Bind message passing socket to rwdtinker application def runcontrolcommand require 'socket' # Change this line... -ip = '127.0.0.1' + ip = '127.0.0.1' # And this one... -port = $rwdcontrolport1 -if @a_remoteportinput -port = @a_remoteportinput.to_i -end -# Done! + port = $rwdcontrolport1 + if @a_remoteportinput + port = @a_remoteportinput.to_i + end - commandtext = @a_remotecommandinput.to_s - - remotehostnotfound = true - -client = UDPSocket::new() -client.send(commandtext, 0, ip, port) - - -if (commandtext == "stop") -begin + 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 @@ -49,21 +43,24 @@ end if remotehostnotfound @remotecommandresult = "Remote Host not running" end @socket.close -end + # Close the socket after use + client.close() + end -remotehostnotfound = true -if (commandtext == "query") -begin + 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 @@ -80,18 +77,20 @@ puts "Network plugin: An error occured." # Rescue all other errors end @socket.close -end - if remotehostnotfound - @remotecommandresult = "Remote Host not running" - end + # 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