Firstly, introduction on my situation.
I decided to attempt to learn C++ (again) and ended up looking at SFML.
Im planning on porting a flash client, ive done it before in another language, though I did only the TCP parts, never made the GUI or anything.
So I decided the logical place to start would be porting over the TCP stuff, as I already know it from before.
Anyway, ive spent the last few hours looking at
http://www.sfml-dev.org/tutorials/1.6/network-sockets.php and the next few pages and ive sort of got "something" working.
This was just a test to figure out how to get the OnReceive working, which pretty much failed.
#include <SFML/Network.hpp>
#include <SFML/System.hpp>
#include <iostream>
class MyEncryptedPacket : public sf::Packet{
private :
virtual void OnReceive(){
std::cout << "received" << std::endl;
}
};
void runClient(){
sf::SocketTCP Client;
if (!Client.Connect(80, "175.107.140.28"))
std::cout << "test" << std::endl;//return;
std::cout << "Connected to server " << std::endl;
char Buffer[] = "GET / HTTP/1.1\r\nHost: www.azkay.com\r\n\r\n";
if (Client.Send(Buffer, sizeof(Buffer)) != sf::Socket::Done)
return;
/*char Buffer2[1024];
std::size_t Received;
if (Client.Receive(Buffer2, sizeof(Buffer2), Received) != sf::Socket::Done){
}
std::cout << Buffer2 << std::endl;*/
sf::Packet RegularPacket;
if (Client.Receive(RegularPacket) != sf::Socket::Done)
return;
MyEncryptedPacket EncryptedPacket;
if (Client.Receive(EncryptedPacket) != sf::Socket::Done)
return;
Client.Close();
};
int main(){
runClient();
std::cout << "Press enter to exit..." << std::endl;
std::cin.ignore(10000, '\n');
return EXIT_SUCCESS;
};
Keeping in mind most of this was "hacked" together with parts from the tutorial pages and its 3am and I started "learning" at around 5pm, I could be just not taking anything in properly and the whole beginner "background in other languages, 5th try over the last few years at C++, just finished my 6th or so hello world".
Basically, I sent a GET to my azkay.com, it was the only "quick" thing I could think of at the time, anything to test out the receive.
I just cant figure out exactly what "tells" it to use the OnReceive.
Also, could also be due to 3am, if I use:
if (!Client.Connect(80, "175.107.140.28"))
return;
It seems to exit runClient once it hits that, the return gets called. Shouldnt that only be called if theres an error in the connect?
If I take the return out and replace it with anything; eg; the cout, it keeps going and "works".
Also, if I uncomment out the commented receive, I see the response fine there, so im really confused at why the .Connect is "erroring". Is there anything I can output that tells me the error code?
Once again, if anything needs clarification just tell me, 3am, probably not making much sense.
Thanks
EDIT::While im here;
In my original "port", I would send packets something like this:
TCPSend($Socket, StringToHex("S55FLASH10") & "00")
So, I would be sending 53353502464C415348023102300300 to the server, not the plaintext.
How would I do this? Same as the other one, just convert the string first?