#network require 'socket' # Network stuff require 'timeout' # Timeout functions def network_start if RUBY_PLATFORM != "i386-mswin32" processone = fork { network_demon } Process.detach(processone) else puts "fork not tried winXP?" end @viewremotecommandresult = "starting controller on next available port" end def network_demon # Find configuration variables host = "127.0.0.1" port = $rwdcontrolports[0].to_i openportfound = false until openportfound # Create a socket to listen on and bind it to the host and port begin @socket = UDPSocket::new() @socket.bind(host, port) # Rescue the "Address in use" error openportfound = true rescue Errno::EADDRINUSE puts "controller startup: Port #{port} on host #{host} is already in use." port=port+1 # Rescue the "Address not available' error rescue Errno::EADDRNOTAVAIL puts "Network plugin: Address #{host} is not available to bind." port=port+1 # Rescue "permission denied errors rescue Errno::EACCES puts "controller startup: Access denied when binding interface addresses. Did you try to bind a port under 1024 as a regular user?" port=port+1 # Rescue all other errors rescue puts "Network plugin: An error occured." port = port+1 # Rescue all other errors end end # Get all acceptable hosts hosts = ["localhost","vaio-sag"] # Do some nice errorchecking if(hosts.type != Array) puts "Network plugin: No hosts found in networkConfig/acceptHosts. Shutting down plugin." return -1 # Return the errorcode for plugin failure end # Main loop while(true) # Get data and client data from the client data, info = @socket.recvfrom(256) # Is this an acceptable IP address? if(hosts.include?(info[2]) || hosts.include?(info[3])) command, parameter = data.split(';') # Command actions command.downcase!() case command when 'stop' @socket.send("hello world",0,info[3],info[1].to_i) when 'query' @socket.send("#{$rwdapplicationidentity} on port #{$port}",0,info[3],info[1].to_i) end # case command end # Access control if end # while(true) end # Network::start()