if (websocket) websocket->close();
Scene* Title::createScene()
auto scene = Scene::create();
auto layer = Title::create();
// on "init" you need to initialize your instance
window_size = Director::getInstance()->getWinSize();
status = LabelTTF::create("In connection...", "Arial", 15);
status->setPosition(Point(window_size.width / 2 , window_size.height / 2));
void Title::loadWebSocket()
websocket = new WebSocket();
websocket->init(*this, "ws://domain.com:8080/echo");
void Title::onOpen(WebSocket* ws)
status->setString("Successful connection");
scheduleOnce(schedule_selector(Title::sendMessage), 1.0f);
void Title::onMessage(WebSocket* ws, const WebSocket::Data& data)
auto *text = String::createWithFormat("%s", data.bytes);
status->setString(text->getCString());
void Title::onClose(WebSocket* ws)
status->setString("Closed connection");
void Title::onError(WebSocket* ws, const WebSocket::ErrorCode& error)
sprintf(buf, "Error code: %d", error);
void Title::sendMessage(float dt)
if (websocket->getReadyState() == WebSocket::State::OPEN){
status->setString("Send Message");
websocket->send("こんにちわ、ラハルです");