I'm in a big need of a favor. I'm well beyond my deadline but I just can't seem to get this to work. I'm looking for a java server script that's as minimalistic as possible. I'm currently using the below script, but it always seems to lock up the system at 100% cpu after a few minutes and never responds again after the first string gets sent. I need a simple java socket server that will run and respond until it receives a terminating character or I manually close it. All I'm intending to do with the script is launch the file name passed to it from a Flash AS3 socket. Thanks in advance.
Edit: I really can't afford to run one of the free servers already out there. I'm looking for something as simple as the above code that I can manipulate to accomplish what I need as small as possible.Code:import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; import java.io.*; public class simpleServer { private ServerSocket server; private Socket client; private BufferedReader in; private PrintWriter out; public void start() { create(); run(); } private void create() { try { server = new ServerSocket( 9001 ); } catch ( Exception e ) { e.printStackTrace(); System.exit( -1 ); } } // sets up a server socket at PORT and listens to it public void run() { try { client = server.accept(); in = new BufferedReader( new InputStreamReader( client.getInputStream() ) ); out = new PrintWriter( client.getOutputStream() ); } catch ( Exception e ) { e.printStackTrace(); System.exit( 0 ); } String line; while ( true ) { try { line = in.readLine(); if ( line != null ) { System.out.println( "Line received: " + line ); out.write( "Line was received." ); out.flush(); Process child = Runtime.getRuntime().exec(line); line = null; } } catch ( Exception e ) { System.out.println("Error!"); e.printStackTrace(); System.exit( 0 ); } } } protected void finalize() { try { in.close(); server.close(); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } } /** * Entry-point. */ public static void main( String[] args ) { try { simpleServer server = new simpleServer(); server.start(); } catch ( Exception e ) { // if we fail, print wtf happened and exit e.printStackTrace(); System.exit( 0 ); } } }




Reply With Quote