0 Members and 1 Guest are viewing this topic.
#include <SFML/System.hpp>#include <SFML/Network.hpp>#include <iostream>#include <string>#pragma comment(lib,"sfml-network-s-d.lib")#pragma comment(lib,"sfml-system-s-d.lib")using namespace std;#define A2S_INFO "\xFF\xFF\xFF\xFF\x54Source Engine Query"#define A2S_INFO_LENGTH 25//int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpArguments, int NumParameters)int main(){ cout << "PROGRAM STARTING..." << endl; sf::Packet rcvPaket; sf::IPAddress rcvIP; unsigned short rcvPort; cout << A2S_INFO << endl; cout << "CREATING SOCKET..." << endl; sf::SocketUDP sckClient; cout << "SOCKET CREATED!" << endl; cout << "BINDING PORT 6586..." << endl; if(!sckClient.Bind(6586)) { cout << "BIND FAILED !" << endl; system("pause"); return 0; } cout << "PORT 6586 BINDED..." << endl; cout << "SENDING PACKET..." << endl; if(sckClient.Send(A2S_INFO,A2S_INFO_LENGTH,"85.25.35.235",27015) != sf::Socket::Done) { cout << "PACKET SENDING ERROR !" << endl; system("pause"); return 0; } cout << "PACKET SENT!" << endl; //sf::Sleep(1000); cout << "RECEIVING PACKET..." << endl; unsigned int rcvLen; char * data = NULL; if(sckClient.Receive(data,1028,rcvLen,rcvIP,rcvPort) != sf::Socket::Done) { cout << "PACKET RECEIVE ERROR !" << endl; system("pause"); return 0; } //cout << "Data Len: " << rcvLen << " Data: " << data << endl; printf("Data len: %d Data: %s\n",rcvLen,data); cout << "PACKET RECEIVED!" << endl; cout << "CLOSING SOCKET..." << endl; sckClient.Close(); cout << "SOCKET CLOSED!" << endl; cout << "END OF PROGRAM!" << endl; system("pause"); return 0;}
PROGRAM STARTING... TSource Engine QueryCREATING SOCKET...SOCKET CREATED!BINDING PORT 6586...PORT 6586 BINDED...SENDING PACKET...PACKET SENT!RECEIVING PACKET...Cannot receive data from the network (invalid parameters) <-- PROBLEM?PACKET RECEIVE ERROR !Press any key to continue . . .
char data[1028]; sckClient.Receive(data, sizeof(data), ...);