network -> cocos2d::network

This commit is contained in:
minggo 2014-01-02 16:25:35 +08:00
parent fa32569e80
commit 07600bd46b
14 changed files with 55 additions and 30 deletions

View File

@ -32,7 +32,7 @@
#include "platform/CCFileUtils.h"
using namespace cocos2d;
NS_CC_BEGIN
namespace network {
@ -502,4 +502,6 @@ void HttpClient::dispatchResponseCallbacks()
}
NS_CC_END

View File

@ -32,6 +32,8 @@
#include "network/HttpResponse.h"
#include "network/HttpClient.h"
NS_CC_BEGIN
namespace network {
/**
@ -115,4 +117,6 @@ private:
}
NS_CC_END
#endif //__CCHTTPREQUEST_H__

View File

@ -27,6 +27,8 @@
#include "cocos2d.h"
NS_CC_BEGIN
namespace network {
class HttpClient;
@ -231,4 +233,6 @@ protected:
}
NS_CC_END
#endif //__HTTP_REQUEST_H__

View File

@ -28,6 +28,8 @@
#include "cocos2d.h"
#include "network/HttpRequest.h"
NS_CC_BEGIN
namespace network {
/**
@ -179,4 +181,6 @@ protected:
}
NS_CC_END
#endif //__HTTP_RESPONSE_H__

View File

@ -32,7 +32,7 @@
#include "HttpClient.h"
#include <algorithm>
using namespace cocos2d;
NS_CC_BEGIN
namespace network {
@ -687,4 +687,6 @@ void SocketIO::removeSocket(const std::string& uri)
_sockets.erase(uri);
}
}
}
NS_CC_END

View File

@ -61,6 +61,8 @@ in the onClose method the pointer should be set to NULL or used to connect to a
#include "cocos2d.h"
NS_CC_BEGIN
namespace network {
//forward declarations
@ -185,4 +187,6 @@ public:
}
NS_CC_END
#endif /* defined(__CC_JSB_SOCKETIO_H__) */

View File

@ -37,7 +37,7 @@
#include "libwebsockets.h"
using namespace cocos2d;
NS_CC_BEGIN
namespace network {
@ -52,7 +52,7 @@ public:
/**
* @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:
WsThreadHelper();
@ -648,3 +648,5 @@ void WebSocket::onUIThreadReceiveMessage(WsMessage* msg)
}
}
NS_CC_END

View File

@ -37,6 +37,8 @@ struct libwebsocket;
struct libwebsocket_context;
struct libwebsocket_protocols;
NS_CC_BEGIN
namespace network {
class WsThreadHelper;
@ -163,4 +165,6 @@ private:
}
NS_CC_END
#endif /* defined(__CC_JSB_WEBSOCKET_H__) */

View File

@ -4,7 +4,7 @@
USING_NS_CC;
USING_NS_CC_EXT;
using namespace network;
using namespace cocos2d::network;
HttpClientTest::HttpClientTest()
: _labelStatusCode(NULL)

View File

@ -20,7 +20,7 @@ public:
void onMenuDeleteTestClicked(cocos2d::Object *sender);
//Http Response Callback
void onHttpRequestCompleted(network::HttpClient *sender, network::HttpResponse *response);
void onHttpRequestCompleted(cocos2d::network::HttpClient *sender, cocos2d::network::HttpResponse *response);
private:
cocos2d::LabelTTF* _labelStatusCode;

View File

@ -12,7 +12,7 @@
USING_NS_CC;
USING_NS_CC_EXT;
using namespace network;
using namespace cocos2d::network;
SocketIOTestLayer::SocketIOTestLayer(void)
: _sioClient(NULL)

View File

@ -14,16 +14,16 @@
class SocketIOTestLayer
: public cocos2d::Layer
, public network::SocketIO::SIODelegate
, public cocos2d::network::SocketIO::SIODelegate
{
public:
SocketIOTestLayer(void);
virtual ~SocketIOTestLayer(void);
virtual void onConnect(network::SIOClient* client);
virtual void onMessage(network::SIOClient* client, const std::string& data);
virtual void onClose(network::SIOClient* client);
virtual void onError(network::SIOClient* client, const std::string& data);
virtual void onConnect(cocos2d::network::SIOClient* client);
virtual void onMessage(cocos2d::network::SIOClient* client, const std::string& data);
virtual void onClose(cocos2d::network::SIOClient* client);
virtual void onError(cocos2d::network::SIOClient* client, const std::string& data);
void toExtensionsMainLayer(cocos2d::Object *sender);
@ -38,10 +38,10 @@ public:
void onMenuTestEndpointDisconnectClicked(cocos2d::Object *sender);
void testevent(network::SIOClient *client, const std::string& data);
void echotest(network::SIOClient *client, const std::string& data);
void testevent(cocos2d::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;
};

View File

@ -11,7 +11,6 @@
USING_NS_CC;
USING_NS_CC_EXT;
using namespace network;
WebSocketTestLayer::WebSocketTestLayer()
: _wsiSendText(NULL)
@ -74,9 +73,9 @@ WebSocketTestLayer::WebSocketTestLayer()
menuBack->setPosition(Point::ZERO);
addChild(menuBack);
_wsiSendText = new WebSocket();
_wsiSendBinary = new WebSocket();
_wsiError = new WebSocket();
_wsiSendText = new network::WebSocket();
_wsiSendBinary = new network::WebSocket();
_wsiError = new network::WebSocket();
if (!_wsiSendText->init(*this, "ws://echo.websocket.org"))
{
@ -202,7 +201,7 @@ void WebSocketTestLayer::toExtensionsMainLayer(cocos2d::Object *sender)
// Menu Callbacks
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...");
_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)
{
if (_wsiSendBinary->getReadyState() == WebSocket::State::OPEN)
if (_wsiSendBinary->getReadyState() == network::WebSocket::State::OPEN)
{
_sendBinaryStatus->setString("Send Binary WS is waiting...");
char buf[] = "Hello WebSocket,\0 I'm\0 a\0 binary\0 message\0.";

View File

@ -15,16 +15,16 @@
class WebSocketTestLayer
: public cocos2d::Layer
, public network::WebSocket::Delegate
, public cocos2d::network::WebSocket::Delegate
{
public:
WebSocketTestLayer();
virtual ~WebSocketTestLayer();
virtual void onOpen(network::WebSocket* ws);
virtual void onMessage(network::WebSocket* ws, const network::WebSocket::Data& data);
virtual void onClose(network::WebSocket* ws);
virtual void onError(network::WebSocket* ws, const network::WebSocket::ErrorCode& error);
virtual void onOpen(cocos2d::network::WebSocket* ws);
virtual void onMessage(cocos2d::network::WebSocket* ws, const cocos2d::network::WebSocket::Data& data);
virtual void onClose(cocos2d::network::WebSocket* ws);
virtual void onError(cocos2d::network::WebSocket* ws, const cocos2d::network::WebSocket::ErrorCode& error);
void toExtensionsMainLayer(cocos2d::Object *sender);
@ -33,9 +33,9 @@ public:
void onMenuSendBinaryClicked(cocos2d::Object *sender);
private:
network::WebSocket* _wsiSendText;
network::WebSocket* _wsiSendBinary;
network::WebSocket* _wsiError;
cocos2d::network::WebSocket* _wsiSendText;
cocos2d::network::WebSocket* _wsiSendBinary;
cocos2d::network::WebSocket* _wsiError;
cocos2d::LabelTTF* _sendTextStatus;
cocos2d::LabelTTF* _sendBinaryStatus;