Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- RakNet::TCPInterface *tcp;
- RakNet::HTTPConnection *httpConnection;
- std::string tHTTPSaddress = "login.server.net";
- std::string tPath = "/";
- std::string tData = "?user=myusername&password=mypassword&version=3";
- std::string tContentType = "application/x-www-form-urlencoded";
- bool Init()
- {
- tcp = RakNet::OP_NEW<RakNet::TCPInterface>(__FILE__, __LINE__);
- tcp->Start(0, 64);
- httpConnection = RakNet::OP_NEW<RakNet::HTTPConnection>(__FILE__, __LINE__);
- httpConnection->Init(tcp, tHTTPSaddress.c_str());
- return true;
- }
- bool Update()
- {
- httpConnection->Update();
- if (RakNet::Packet *packet = tcp->Receive()) {
- httpConnection->ProcessTCPPacket(packet);
- tcp->DeallocatePacket(packet);
- }
- RakSleep(500);
- if (httpConnection->IsBusy()) return true;
- httpConnection->Post(tPath.c_str(),tData.c_str(), tContentType.c_str());
- RakNet::RakString data = httpConnection->Read();
- httpConnection->HasBadResponse(NULL, &data);
- std::cout << data.C_String() << std::endl;
- if (data.IsEmpty()) return true;
- return false;
- }
- void Draw()
- {
- std::string state;
- switch (httpConnection->GetState()) {
- case 0: state = "Waiting"; break;
- case 1: state = "Disconnecting"; break;
- case 2: state = "Connecting"; break;
- case 3: state = "Connected"; break;
- case 4: state = "Processing"; break;
- }
- std::cout << (std::string)state<< std::endl;;
- }
- void Shut() {}
- int main (int argc, char ** argv)
- {
- Init();
- while (Update())
- {
- Draw();
- }
- Shut();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement