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

Trying to open a TCP socket, but raklib crashes

Comments in 'Plugin Development' started by Kripto, Sep 1, 2015.

  1. Kripto
    Offline

    Kripto New Member

    Joined:
    Mar 2, 2014
    Posts:
    15
    Minecraft User:
    Kripto96
    I'm trying to create a new TCP connection via the PHP socket, but when I bind it raklib crashes.

    This is my code, a classic PHP socket:
    PHP:
    public function run() {
        
    $this->socket socket_create(AF_INETSOCK_STREAMSOL_TCP);
            if(@
    socket_bind($this->socketself::HOSTself::PORT)) {
                
    $this->connection socket_connect($this->socketself::HOSTself::PORT);
            }
        }
    }
    This is the crash message:
    Code:
    [17:12:49] [Server thread/CRITICAL]: [Network] Stopped interface pocketmine\network\RakLibInterface due to RakLib Thread crashed [raklib\server\UDPServerSocket]: socket_bind(): unable to bind address [98]: Address already in use
    What's the right way to do this? Is it possible to do?

    P.S. The PHP code I posted works and it does waht is supposed to do.
    PocketKiller and xionbig like this.
  2. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    You can't use the port of your server because it's already in use from it! This is the reason why RakLib crashes!
    The solution is to change the port of the socket to another one which is not in use
    PocketKiller and luca28pet like this.
  3. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    That code will block your server so you should run it from an AsyncTask.
    PocketKiller and luca28pet like this.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Wait, why is the error UDP?
  5. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Because he was trying to open the TCP socket on the same port where RakLib was listening to and so the RakLib UDP Socket crashed
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    But UDP and TCP ports are different.
    SeifValkierks and EvolSoft like this.
  7. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    Actually, I don't understand the code here. If you want to connect to another port, you don't really need to do a "socket_bind".

    BTW, UDP and TCP ports are different, but if RCON is enabled, PocketMine will create an UDP and a TCP ports.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why UDPServerSocket then?

Share This Page

Advertisement