Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - azkay

Pages: [1]
1
System / Best way to setup GUI/TCP?
« on: October 31, 2010, 08:42:19 am »
Right now ive got a while loop in main() that loops a tcpreceive and parses the data from there, eg;

loop start
recv
switch recv
case 1:
move person left
case 2:
move person right
default:

loop end

Now, using the tutorial on using a sprite, I would want to code it so, when it receives a "move left" packet, it moves the sprite to the left.

I tried putting it all in the same receive loop, but there was lots of delay in there, so, I need two threads?

Whats the best way to setup multiple threads where data can still be accessed by either?

eg; One thread runs the OpenGL GUI loop, other thread runs the TCP receiving?

2
Network / How do I use OnReceive? Also, Client.Connect problem
« on: October 15, 2010, 06:47:51 pm »
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.

Code: [Select]

#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:
Code: [Select]

    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:
Code: [Select]

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?

Pages: [1]
anything