Skip to content

Instantly share code, notes, and snippets.

@yuyaprgrm
Last active May 12, 2019 14:07
Show Gist options
  • Select an option

  • Save yuyaprgrm/00e655754585016d59dddbaaa69950c5 to your computer and use it in GitHub Desktop.

Select an option

Save yuyaprgrm/00e655754585016d59dddbaaa69950c5 to your computer and use it in GitHub Desktop.
PocketMine-MPのAsyncTaskのサンプル
<?php
/**
* Created by PhpStorm.
* User: tokai
* Date: 2018/03/01
* Time: 19:35
*/
namespace MasterF\PocketMineGUI\task;
use pocketmine\scheduler\AsyncTask;
use pocketmine\Server;
class GUIConnectionTask extends AsyncTask
{
/**
* Actions to execute when run
*
* @return void
*/
public function onRun()
{
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
// socket_bind($sock, "127.0.0.1");
socket_connect($sock, "127.0.0.1",20132);
$message = socket_read($sock, 512, PHP_NORMAL_READ);
$this->setResult($message, false);
}
public function onCompletion(Server $server)
{
$message = $this->getResult();
$server->getLogger()->info("From PocketMineGUI: ${message}");
}
}
@belohnung
Copy link

gay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment