connection is now working properly
This commit is contained in:
parent
8d1281b316
commit
6f952adae2
|
@ -76,7 +76,7 @@ void Engine::run()
|
||||||
Platform::poll();
|
Platform::poll();
|
||||||
|
|
||||||
//poll network events
|
//poll network events
|
||||||
//logDebug("%d", g_connections.poll());
|
g_connections.poll();
|
||||||
|
|
||||||
// update before redering
|
// update before redering
|
||||||
ticks = Platform::getTicks();
|
ticks = Platform::getTicks();
|
||||||
|
@ -107,23 +107,6 @@ void Engine::run()
|
||||||
|
|
||||||
// swap buffers
|
// swap buffers
|
||||||
Platform::swapBuffers();
|
Platform::swapBuffers();
|
||||||
|
|
||||||
/*
|
|
||||||
static ConnectionPtr connection = g_connections.createConnection();
|
|
||||||
|
|
||||||
if(connection->getLastError()){
|
|
||||||
logError("%s", connection->getLastError().message().c_str());
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if(!connection->isConnecting() && !connection->isConnected()){
|
|
||||||
connection->connect("www.google.com.br", 80);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!connection->isConnected()){
|
|
||||||
logDebug("still not connected.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,16 +57,18 @@ void Connection::connect(const std::string& ip, uint16 port)
|
||||||
logDebug("connecting...");
|
logDebug("connecting...");
|
||||||
|
|
||||||
//first resolve dns
|
//first resolve dns
|
||||||
boost::asio::ip::tcp::resolver::query query(ip, "80");
|
boost::asio::ip::tcp::resolver::query query(ip, convertType<std::string, uint16>(port));
|
||||||
m_resolver.async_resolve(query, boost::bind(&Connection::onResolveDns, this, boost::asio::placeholders::error, boost::asio::placeholders::iterator));
|
m_resolver.async_resolve(query, boost::bind(&Connection::onResolveDns, this, boost::asio::placeholders::error, boost::asio::placeholders::iterator));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::onResolveDns(const boost::system::error_code& error, boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
|
void Connection::onResolveDns(const boost::system::error_code& error, boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
|
||||||
{
|
{
|
||||||
logDebug("resolving dns..");
|
logDebug("resolving dns..");
|
||||||
|
|
||||||
|
m_lastError = error;
|
||||||
|
|
||||||
if(error){
|
if(error){
|
||||||
m_connecting = false;
|
m_connecting = false;
|
||||||
m_lastError = error;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,9 +78,10 @@ void Connection::onResolveDns(const boost::system::error_code& error, boost::asi
|
||||||
|
|
||||||
void Connection::onConnect(const boost::system::error_code& error)
|
void Connection::onConnect(const boost::system::error_code& error)
|
||||||
{
|
{
|
||||||
|
m_lastError = error;
|
||||||
|
|
||||||
if(error){
|
if(error){
|
||||||
m_connecting = false;
|
m_connecting = false;
|
||||||
m_lastError = error;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@ public:
|
||||||
|
|
||||||
const boost::system::error_code& getLastError() const { return m_lastError; }
|
const boost::system::error_code& getLastError() const { return m_lastError; }
|
||||||
|
|
||||||
|
void resetLastError() { m_lastError = boost::system::error_code(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onResolveDns(const boost::system::error_code& error, boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
|
void onResolveDns(const boost::system::error_code& error, boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
|
||||||
void onConnect(const boost::system::error_code& error);
|
void onConnect(const boost::system::error_code& error);
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "framework/engine.h"
|
#include "framework/engine.h"
|
||||||
#include "framework/rect.h"
|
#include "framework/rect.h"
|
||||||
#include "framework/fonts.h"
|
#include "framework/fonts.h"
|
||||||
|
#include "framework/net/connections.h"
|
||||||
|
|
||||||
TexturePtr background;
|
TexturePtr background;
|
||||||
|
|
||||||
|
@ -37,6 +38,9 @@ void MenuState::onEnter()
|
||||||
{
|
{
|
||||||
m_background = g_textures.get("background.png");
|
m_background = g_textures.get("background.png");
|
||||||
m_background->enableBilinearFilter();
|
m_background->enableBilinearFilter();
|
||||||
|
|
||||||
|
m_connection = g_connections.createConnection();
|
||||||
|
m_connection->connect("www.google.com.br", 80);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuState::onLeave()
|
void MenuState::onLeave()
|
||||||
|
@ -74,5 +78,8 @@ void MenuState::render()
|
||||||
|
|
||||||
void MenuState::update(int ticks, int elapsedTicks)
|
void MenuState::update(int ticks, int elapsedTicks)
|
||||||
{
|
{
|
||||||
|
if(m_connection->getLastError()){
|
||||||
|
logError("%s", m_connection->getLastError().message().c_str());
|
||||||
|
m_connection->resetLastError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include "framework/gamestate.h"
|
#include "framework/gamestate.h"
|
||||||
#include "framework/texture.h"
|
#include "framework/texture.h"
|
||||||
|
#include "framework/net/connection.h"
|
||||||
|
|
||||||
class MenuState : public GameState
|
class MenuState : public GameState
|
||||||
{
|
{
|
||||||
|
@ -45,6 +46,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TexturePtr m_background;
|
TexturePtr m_background;
|
||||||
|
ConnectionPtr m_connection;
|
||||||
|
int m_connectionTicks;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MENUSTATE_H
|
#endif // MENUSTATE_H
|
||||||
|
|
Loading…
Reference in New Issue