Plugin receives message from webserver, but webserver not from plugin

Discussion in 'Plugin Development' started by robin0van0der0v, Jun 21, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    robin0van0der0v

    Hello everybody,

    I have another problem with my plugin.
    A PHP-script on my webserver sends data to my plugin, the plugin receives it and logs it to the console.
    But, when the plugin tries to send other data back to the running PHP script it doesn't receive the other data.
    It gives no error in the plugin but one error in the PHP-script:
    Fatal error: Maximum execution time of 60 seconds exceeded on line 17

    This is the Java-code:
    Code:
    public void run()
    {
        ServerSocket serversocket = null;
        try
        {
            serversocket = new ServerSocket(55555);
        }
        catch (IOException e)
        {
            plugin.log.severe("Could not listen on port 55555!");
            plugin.log.severe("Error: "+e);
            e.printStackTrace();
            plugin.getPluginLoader().disablePlugin(plugin);
        }
    
        while (true)
        {
            Socket clientsocket = null;
            try
            {
                clientsocket = serversocket.accept();
            }
            catch (IOException e)
            {
                plugin.log.severe("Accept failed!");
                plugin.log.severe("Error: "+e);
                e.printStackTrace();
                break;
            }
    
            BufferedReader in = null;
            PrintWriter out = null;
            try
            {
                in = new BufferedReader(new InputStreamReader(clientsocket.getInputStream()));
                out = new PrintWriter(clientsocket.getOutputStream(),true);
            }
            catch (IOException e)
            {
                plugin.log.severe("Could not create output stream!");
                plugin.log.severe("Error: "+e);
                e.printStackTrace();
                break;
            }
    
            try
            {
                String line = null;
                while ((line = in.readLine()) != null)
                {
                    plugin.log.info("[Message] "+line);
                }
                in.close();
            }
            catch (IOException e)
            {
                plugin.log.severe("Could not listen to stream!");
                plugin.log.severe("Error: "+e);
                e.printStackTrace();
                break;
            }
    
            out.println("Returned");
            out.println("message");
            out.println("!");
            out.flush();
            out.close();
    
            try
            {
                clientsocket.close();
            }
            catch (IOException e)
            {
                plugin.log.severe("Could not close client socket!");
                plugin.log.severe("Error: "+e);
                e.printStackTrace();
                break;
            }
        }
    
        try
        {
            serversocket.close();
        }
        catch (IOException e)
        {
            plugin.log.severe("Could not close server socket!");
            plugin.log.severe("Error: "+e);
            e.printStackTrace();
        }
    }
    And this is my PHP-script on my webserver:
    PHP:
    <?php

    $fp 
    fsockopen("localhost",55555,$errno,$errstr,5);
    if (!
    $fp)
    {
        echo 
    $errstr." (".$errno.")";
    }
    else
    {
        
    $out "Message\r\n";
        
    $out .= "comes\r\n";
        
    $out .= "Here\r\n";
        
    $out .= "!";
        
    fwrite($fp,$out);

        while (!
    feof($fp))
        {
            echo 
    fgets($fp,128);
        }

        
    fclose($fp);
    }

    ?>

    ~ Robin.
     
  2. Offline

    Daviidi

    I'm not certain, but I think in.close() closes the underlying stream, and therefore it cannot send the data to the php script.
     
  3. Offline

    robin0van0der0v

    I tried to set "in.close();" after the sending, but it still gives the same result. :(
     
  4. Offline

    robin0van0der0v

    I still can't get it working. :(
    Can somebody help me? :p
     
Thread Status:
Not open for further replies.

Share This Page