mirror of https://github.com/axmolengine/axmol.git
network -> cocos2d::network
This commit is contained in:
parent
fa32569e80
commit
07600bd46b
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
#include "platform/CCFileUtils.h"
|
#include "platform/CCFileUtils.h"
|
||||||
|
|
||||||
using namespace cocos2d;
|
NS_CC_BEGIN
|
||||||
|
|
||||||
namespace network {
|
namespace network {
|
||||||
|
|
||||||
|
@ -502,4 +502,6 @@ void HttpClient::dispatchResponseCallbacks()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
#include "network/HttpResponse.h"
|
#include "network/HttpResponse.h"
|
||||||
#include "network/HttpClient.h"
|
#include "network/HttpClient.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
namespace network {
|
namespace network {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,4 +117,6 @@ private:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
#endif //__CCHTTPREQUEST_H__
|
#endif //__CCHTTPREQUEST_H__
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
|
|
||||||
#include "cocos2d.h"
|
#include "cocos2d.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
namespace network {
|
namespace network {
|
||||||
|
|
||||||
class HttpClient;
|
class HttpClient;
|
||||||
|
@ -231,4 +233,6 @@ protected:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
#endif //__HTTP_REQUEST_H__
|
#endif //__HTTP_REQUEST_H__
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
#include "cocos2d.h"
|
#include "cocos2d.h"
|
||||||
#include "network/HttpRequest.h"
|
#include "network/HttpRequest.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
namespace network {
|
namespace network {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -179,4 +181,6 @@ protected:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
#endif //__HTTP_RESPONSE_H__
|
#endif //__HTTP_RESPONSE_H__
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include "HttpClient.h"
|
#include "HttpClient.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace cocos2d;
|
NS_CC_BEGIN
|
||||||
|
|
||||||
namespace network {
|
namespace network {
|
||||||
|
|
||||||
|
@ -688,3 +688,5 @@ void SocketIO::removeSocket(const std::string& uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
|
@ -61,6 +61,8 @@ in the onClose method the pointer should be set to NULL or used to connect to a
|
||||||
|
|
||||||
#include "cocos2d.h"
|
#include "cocos2d.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
namespace network {
|
namespace network {
|
||||||
|
|
||||||
//forward declarations
|
//forward declarations
|
||||||
|
@ -185,4 +187,6 @@ public:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
#endif /* defined(__CC_JSB_SOCKETIO_H__) */
|
#endif /* defined(__CC_JSB_SOCKETIO_H__) */
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
#include "libwebsockets.h"
|
#include "libwebsockets.h"
|
||||||
|
|
||||||
using namespace cocos2d;
|
NS_CC_BEGIN
|
||||||
|
|
||||||
namespace network {
|
namespace network {
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* @brief Websocket thread helper, it's used for sending message between UI thread and websocket thread.
|
* @brief Websocket thread helper, it's used for sending message between UI thread and websocket thread.
|
||||||
*/
|
*/
|
||||||
class WsThreadHelper : public cocos2d::Object
|
class WsThreadHelper : public Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WsThreadHelper();
|
WsThreadHelper();
|
||||||
|
@ -648,3 +648,5 @@ void WebSocket::onUIThreadReceiveMessage(WsMessage* msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
|
@ -37,6 +37,8 @@ struct libwebsocket;
|
||||||
struct libwebsocket_context;
|
struct libwebsocket_context;
|
||||||
struct libwebsocket_protocols;
|
struct libwebsocket_protocols;
|
||||||
|
|
||||||
|
NS_CC_BEGIN
|
||||||
|
|
||||||
namespace network {
|
namespace network {
|
||||||
|
|
||||||
class WsThreadHelper;
|
class WsThreadHelper;
|
||||||
|
@ -163,4 +165,6 @@ private:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_CC_END
|
||||||
|
|
||||||
#endif /* defined(__CC_JSB_WEBSOCKET_H__) */
|
#endif /* defined(__CC_JSB_WEBSOCKET_H__) */
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
USING_NS_CC;
|
USING_NS_CC;
|
||||||
USING_NS_CC_EXT;
|
USING_NS_CC_EXT;
|
||||||
using namespace network;
|
using namespace cocos2d::network;
|
||||||
|
|
||||||
HttpClientTest::HttpClientTest()
|
HttpClientTest::HttpClientTest()
|
||||||
: _labelStatusCode(NULL)
|
: _labelStatusCode(NULL)
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
void onMenuDeleteTestClicked(cocos2d::Object *sender);
|
void onMenuDeleteTestClicked(cocos2d::Object *sender);
|
||||||
|
|
||||||
//Http Response Callback
|
//Http Response Callback
|
||||||
void onHttpRequestCompleted(network::HttpClient *sender, network::HttpResponse *response);
|
void onHttpRequestCompleted(cocos2d::network::HttpClient *sender, cocos2d::network::HttpResponse *response);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cocos2d::LabelTTF* _labelStatusCode;
|
cocos2d::LabelTTF* _labelStatusCode;
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
USING_NS_CC;
|
USING_NS_CC;
|
||||||
USING_NS_CC_EXT;
|
USING_NS_CC_EXT;
|
||||||
using namespace network;
|
using namespace cocos2d::network;
|
||||||
|
|
||||||
SocketIOTestLayer::SocketIOTestLayer(void)
|
SocketIOTestLayer::SocketIOTestLayer(void)
|
||||||
: _sioClient(NULL)
|
: _sioClient(NULL)
|
||||||
|
|
|
@ -14,16 +14,16 @@
|
||||||
|
|
||||||
class SocketIOTestLayer
|
class SocketIOTestLayer
|
||||||
: public cocos2d::Layer
|
: public cocos2d::Layer
|
||||||
, public network::SocketIO::SIODelegate
|
, public cocos2d::network::SocketIO::SIODelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SocketIOTestLayer(void);
|
SocketIOTestLayer(void);
|
||||||
virtual ~SocketIOTestLayer(void);
|
virtual ~SocketIOTestLayer(void);
|
||||||
|
|
||||||
virtual void onConnect(network::SIOClient* client);
|
virtual void onConnect(cocos2d::network::SIOClient* client);
|
||||||
virtual void onMessage(network::SIOClient* client, const std::string& data);
|
virtual void onMessage(cocos2d::network::SIOClient* client, const std::string& data);
|
||||||
virtual void onClose(network::SIOClient* client);
|
virtual void onClose(cocos2d::network::SIOClient* client);
|
||||||
virtual void onError(network::SIOClient* client, const std::string& data);
|
virtual void onError(cocos2d::network::SIOClient* client, const std::string& data);
|
||||||
|
|
||||||
void toExtensionsMainLayer(cocos2d::Object *sender);
|
void toExtensionsMainLayer(cocos2d::Object *sender);
|
||||||
|
|
||||||
|
@ -38,10 +38,10 @@ public:
|
||||||
void onMenuTestEndpointDisconnectClicked(cocos2d::Object *sender);
|
void onMenuTestEndpointDisconnectClicked(cocos2d::Object *sender);
|
||||||
|
|
||||||
|
|
||||||
void testevent(network::SIOClient *client, const std::string& data);
|
void testevent(cocos2d::network::SIOClient *client, const std::string& data);
|
||||||
void echotest(network::SIOClient *client, const std::string& data);
|
void echotest(cocos2d::network::SIOClient *client, const std::string& data);
|
||||||
|
|
||||||
network::SIOClient *_sioClient, *_sioEndpoint;
|
cocos2d::network::SIOClient *_sioClient, *_sioEndpoint;
|
||||||
|
|
||||||
cocos2d::LabelTTF *_sioClientStatus;
|
cocos2d::LabelTTF *_sioClientStatus;
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
USING_NS_CC;
|
USING_NS_CC;
|
||||||
USING_NS_CC_EXT;
|
USING_NS_CC_EXT;
|
||||||
using namespace network;
|
|
||||||
|
|
||||||
WebSocketTestLayer::WebSocketTestLayer()
|
WebSocketTestLayer::WebSocketTestLayer()
|
||||||
: _wsiSendText(NULL)
|
: _wsiSendText(NULL)
|
||||||
|
@ -74,9 +73,9 @@ WebSocketTestLayer::WebSocketTestLayer()
|
||||||
menuBack->setPosition(Point::ZERO);
|
menuBack->setPosition(Point::ZERO);
|
||||||
addChild(menuBack);
|
addChild(menuBack);
|
||||||
|
|
||||||
_wsiSendText = new WebSocket();
|
_wsiSendText = new network::WebSocket();
|
||||||
_wsiSendBinary = new WebSocket();
|
_wsiSendBinary = new network::WebSocket();
|
||||||
_wsiError = new WebSocket();
|
_wsiError = new network::WebSocket();
|
||||||
|
|
||||||
if (!_wsiSendText->init(*this, "ws://echo.websocket.org"))
|
if (!_wsiSendText->init(*this, "ws://echo.websocket.org"))
|
||||||
{
|
{
|
||||||
|
@ -202,7 +201,7 @@ void WebSocketTestLayer::toExtensionsMainLayer(cocos2d::Object *sender)
|
||||||
// Menu Callbacks
|
// Menu Callbacks
|
||||||
void WebSocketTestLayer::onMenuSendTextClicked(cocos2d::Object *sender)
|
void WebSocketTestLayer::onMenuSendTextClicked(cocos2d::Object *sender)
|
||||||
{
|
{
|
||||||
if (_wsiSendText->getReadyState() == WebSocket::State::OPEN)
|
if (_wsiSendText->getReadyState() == network::WebSocket::State::OPEN)
|
||||||
{
|
{
|
||||||
_sendTextStatus->setString("Send Text WS is waiting...");
|
_sendTextStatus->setString("Send Text WS is waiting...");
|
||||||
_wsiSendText->send("Hello WebSocket, I'm a text message.");
|
_wsiSendText->send("Hello WebSocket, I'm a text message.");
|
||||||
|
@ -217,7 +216,7 @@ void WebSocketTestLayer::onMenuSendTextClicked(cocos2d::Object *sender)
|
||||||
|
|
||||||
void WebSocketTestLayer::onMenuSendBinaryClicked(cocos2d::Object *sender)
|
void WebSocketTestLayer::onMenuSendBinaryClicked(cocos2d::Object *sender)
|
||||||
{
|
{
|
||||||
if (_wsiSendBinary->getReadyState() == WebSocket::State::OPEN)
|
if (_wsiSendBinary->getReadyState() == network::WebSocket::State::OPEN)
|
||||||
{
|
{
|
||||||
_sendBinaryStatus->setString("Send Binary WS is waiting...");
|
_sendBinaryStatus->setString("Send Binary WS is waiting...");
|
||||||
char buf[] = "Hello WebSocket,\0 I'm\0 a\0 binary\0 message\0.";
|
char buf[] = "Hello WebSocket,\0 I'm\0 a\0 binary\0 message\0.";
|
||||||
|
|
|
@ -15,16 +15,16 @@
|
||||||
|
|
||||||
class WebSocketTestLayer
|
class WebSocketTestLayer
|
||||||
: public cocos2d::Layer
|
: public cocos2d::Layer
|
||||||
, public network::WebSocket::Delegate
|
, public cocos2d::network::WebSocket::Delegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WebSocketTestLayer();
|
WebSocketTestLayer();
|
||||||
virtual ~WebSocketTestLayer();
|
virtual ~WebSocketTestLayer();
|
||||||
|
|
||||||
virtual void onOpen(network::WebSocket* ws);
|
virtual void onOpen(cocos2d::network::WebSocket* ws);
|
||||||
virtual void onMessage(network::WebSocket* ws, const network::WebSocket::Data& data);
|
virtual void onMessage(cocos2d::network::WebSocket* ws, const cocos2d::network::WebSocket::Data& data);
|
||||||
virtual void onClose(network::WebSocket* ws);
|
virtual void onClose(cocos2d::network::WebSocket* ws);
|
||||||
virtual void onError(network::WebSocket* ws, const network::WebSocket::ErrorCode& error);
|
virtual void onError(cocos2d::network::WebSocket* ws, const cocos2d::network::WebSocket::ErrorCode& error);
|
||||||
|
|
||||||
void toExtensionsMainLayer(cocos2d::Object *sender);
|
void toExtensionsMainLayer(cocos2d::Object *sender);
|
||||||
|
|
||||||
|
@ -33,9 +33,9 @@ public:
|
||||||
void onMenuSendBinaryClicked(cocos2d::Object *sender);
|
void onMenuSendBinaryClicked(cocos2d::Object *sender);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
network::WebSocket* _wsiSendText;
|
cocos2d::network::WebSocket* _wsiSendText;
|
||||||
network::WebSocket* _wsiSendBinary;
|
cocos2d::network::WebSocket* _wsiSendBinary;
|
||||||
network::WebSocket* _wsiError;
|
cocos2d::network::WebSocket* _wsiError;
|
||||||
|
|
||||||
cocos2d::LabelTTF* _sendTextStatus;
|
cocos2d::LabelTTF* _sendTextStatus;
|
||||||
cocos2d::LabelTTF* _sendBinaryStatus;
|
cocos2d::LabelTTF* _sendBinaryStatus;
|
||||||
|
|
Loading…
Reference in New Issue