Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Volt 3.1.0

Painless web server for PocketMine

  1. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    while($this->running and is_resource($this->sk)){
                
    $con socket_accept($this->sk);
                
    console("Resource received");
                
    $page trim(socket_read($con2048PHP_NORMAL_READ));
                
    console($page);
                
    $action strstr($page" "true);
                
    $path strstr($page" ");
                
    $file FILE_PATH."site".strstr($path" "true);
                
    console($file);
                
    socket_write($con"File not found.");
                
    socket_close($con);
            }
    I wrote something like your plugin, and socket was received $file was correctly parsed. But why does it say "This webpage is not available"?
    Last edited: May 19, 2014
  2. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Are you closing $con with every connection?
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Aren't you doing that?
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Yeah, but you have a brace before you do it, so I am not sure if you are closing after the while loop ends.
  5. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    If you are closing it properly I don't know what's going awry :(
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I just copied it and deleted some lines, and that close brace was a forgotten line.
  7. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Have you set the socket to non blocking?
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    How do I do that?
  9. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    You shouldn't if it is in a separate thread, if it's non blocking then socket_accecpt would return false when there was no connection.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I didn't thread it because there is only one thread. (100% http server)
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    In fact I should've used explode(), but this is what a copycat does :p
  12. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Does it work when you just call accept, write and then close?
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No
  14. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    How are you configuring the socket?
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    My file:
    PHP:
    <?php

    class Server{
        public 
    $running true;
        public 
    $sk;
        public function 
    __construct(){
            
    $this->sk socket_create(AF_INETSOCK_STREAMSOL_TCP);
            
    // $port = getopt("p::");
            // if($port === false){
                
    $port 8080;
            
    // }
            // else{
                // $port = $port[0];
            // }
            
    $this->port $port;
            if(
    socket_bind($this->sk"0.0.0.0"$port) === false){
                
    console("Unable to bind socket to $port. Stopping server.");
                
    $this->running false;
            }
            if(
    socket_listen($this->sk5) === false){
                
    console("Socket listen returned false.");
                
    $this->running false;
            }
        }
        public function 
    start(){
            while(
    $this->running and is_resource($this->sk)){
                
    $con socket_accept($this->sk);
                
    console("Resource received");
                
    $page trim(socket_read($con2048PHP_NORMAL_READ));
                
    console("Page: ");
                
    console($page);
                
    $page explode(" "$page);
                
    $action $page[0];
                
    $file $page[1];
                
    $file FILE_PATH."site".$file;
                
    console("File: ");
                
    console($file);
                if(!
    is_file($file)){
                    
    socket_write($con"File not found.");
                    
    console("File not found. written");
                }
                else{
                    
    socket_write($confile_get_contents($file));
                    
    console("Contents in $file written");
                }
                
    socket_close($con);
            }
        }
        public function 
    stop(){
            
    $this->running false;
        }
    }
    And console:
    Code:
    Resource received
    Page:
    GET /index.html HTTP/1.1
    File:
    C:\coding\HTTPServer/site/index.html
    Contents in C:\coding\HTTPServer/site/index.html written
    Resource received
    Page:
    GET /index.html HTTP/1.1
    File:
    C:\coding\HTTPServer/site/index.html
    Contents in C:\coding\HTTPServer/site/index.html written
  16. Pocketart
    Offline

    Pocketart Active Member

    Joined:
    Aug 31, 2013
    Posts:
    55
    Minecraft User:
    Pocketart
    HMmmMmmmMmmmmn
    I put the hello world html file in my "HTTPSERVER" folder
    i went on to play.shauncheon.com:8080 but the website doesnt show up
    it says "could not connect to website"
    help
    additional info:
    (POrt 8080 is forwarded on TCP)
    (I used Chrome to test this)
  17. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,167
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    same issue since few weeks ago ... :-/
  18. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Apparently it isn't working well on some systems (mostly windows), I will attempt to fix it soon :)
    PEMapModder likes this.
  19. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,167
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    not working in Ubuntu 12.04 64BIT also.
  20. BlueCraft
    Offline

    BlueCraft New Member

    Joined:
    May 20, 2014
    Posts:
    30
    Minecraft User:
    BlueCraft
    Whats this plugin actully do?

Share This Page

Advertisement