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.


Messages - azkay

Pages: [1]
1
System / Best way to setup GUI/TCP?
« on: November 05, 2010, 02:59:15 pm »
But, does anyone see where/if I went wrong in the code I posted?

2
SFML website / Switching from phpBB2 to SMF
« on: November 04, 2010, 05:27:37 am »
Quote from: "Mindiell"
Maybe you can have a look at punBB. I used it once and it was a light and simple forum engine. But I'm not sure that it could solve your problems, I don't remember its features exactly.
Better yet, FluxBB.

It doesnt have any of the features you want, but its got loads of mods that fix that problem.

3
System / Best way to setup GUI/TCP?
« on: November 04, 2010, 03:59:32 am »
Still lags whether I set blocking to false or just comment it out.
If I comment out everything within the if(Selector.Wait()), except for the receive, it still lags. Tried increasing the buffer to 1024, still lags.

Im out of ideas.

4
System / Best way to setup GUI/TCP?
« on: November 02, 2010, 09:01:16 am »
Well, after a day of raging I still havnt gotten it working.
Any ideas on how to get it all working properly?

I have taken out the data/user/login/etcetc, so it obviously wont run, same with the custom includes. But hopefully it shouldnt matter for this problem.

Basically, need to get the receive stuff working with the graphics stuff.
Now that im (not?) using threads, dont know if this thread should stay under "Systems", but oh well.

Code: [Select]

#define _CRT_SECURE_NO_WARNINGS

#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/System.hpp>
#include <sstream>
#include "misc.h"
#include "f.h"
#include "md5.h"

sf::SocketTCP Client;
sf::SelectorTCP Selector;

std::string STX = "\x02";
std::string ETX = "\x03";
std::string SOH = "\x01";

int main(){
std::vector<std::string> results;
std::stringstream all;
std::string ReceivedStr;
size_t Size = 0;
char Buffer[1];

std::vector<std::string> gInfo = fLogin("", "");

std::string hood = "";
std::string server = fServer(hood);
Client.Connect(8080, server);
//Client.SetBlocking(false);
Selector.Add(Client);

fSend(Client, "some,data");
fSend(Client, "some,data");
fSend(Client, "some,data");

sf::Event Event;
sf::RenderWindow App(sf::VideoMode(1024, 1024, 32), "SFML Graphics");

sf::Image Map;
sf::Image avatarMe;

Map.LoadFromFile("image1.jpg");
avatarMe.LoadFromFile("1aff79cba4bac.png");

sf::Sprite Flash(Map);
sf::Sprite Sprite(avatarMe);

while(App.IsOpened()){
while(App.GetEvent(Event)){
if (Event.Type == sf::Event::Closed)
App.Close();
}

float ElapsedTime = App.GetFrameTime();

if (App.GetInput().IsKeyDown(sf::Key::Left))  Sprite.Move(-100 * ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::Right)) Sprite.Move( 100 * ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::Up))    Sprite.Move(0, -100 * ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::Down))  Sprite.Move(0,  100 * ElapsedTime);

App.Clear();
App.Draw(Flash);
App.Draw(Sprite);
App.Display();

if(Selector.Wait()){
Client.Receive(Buffer, sizeof(Buffer), Size);
ReceivedStr.append(Buffer, Buffer + Size);
if(Size <= sizeof(Buffer)){
if(ReceivedStr != ETX){
all << ReceivedStr;
}else{
if(all.str().length() > 2){
if(!isdigit(all.str().substr(0, 1)[0]))
all.str(all.str().substr(1, all.str().length()));

StringExplode(all.str(), STX, &results);
switch(atoi(results[0].c_str())){
case 35:
std::cout << all.str() << std::endl;
break;

default:
std::cout << all.str() << std::endl;
break;
}
}
all.str("");
}
ReceivedStr = "";
results.clear();
}
}
}

std::cout << "Press enter to exit..." << std::endl;
    std::cin.ignore(10000, '\n');
Client.Close();

    return EXIT_SUCCESS;
}

5
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?

6
Network / How do I use OnReceive? Also, Client.Connect problem
« on: October 16, 2010, 09:28:23 am »
New day, catching on faster.
Ive been awake for maybe 30 minutes and things are already clearer.

Thanks to (http://www.sfml-dev.org/forum/viewtopic.php?t=1581), I think ive gotten the "receiver" finished, as in, "working".

Code: [Select]

#include <SFML/Network.hpp>
#include <iostream>
#include <string>

int main(){
sf::SocketTCP Client;
std::string ReceivedStr;

Client.Connect(8080, "");

char Buffers[] = "S55FLASH10";
Client.Send(Buffers, sizeof(Buffers));
size_t Size = 0;

while(1){
char Buffer[1024];
while(Client.Receive(Buffer, sizeof(Buffer), Size) == sf::Socket::Done){
ReceivedStr.append(Buffer, Buffer + Size);
if (Size < sizeof(Buffer)){
std::cout << ReceivedStr << std::endl;
ReceivedStr = "";
break;
}
}
}

    std::cout << "Press enter to exit..." << std::endl;
    std::cin.ignore(10000, '\n');
Client.Close();

    return EXIT_SUCCESS;
};

7
Network / How do I use OnReceive? Also, Client.Connect problem
« on: October 15, 2010, 08:01:25 pm »
aaaaah this is so confusing.

Dont suppose I could get a quick "example" of a receiver client?
Basically;

Connects to a server
Sends a packet

start loop
if receive != "" echo receive;
endloop

So, it would connect to IP:PORT, send a packet, then keep looping a "receiver", if the data received isnt blank, then show it?

Ive just coded another page of something that is just confusing me.
And with that, im going to bed before I throw something at my monitor.

Night.

8
Network / How do I use OnReceive? Also, Client.Connect problem
« on: October 15, 2010, 07:11:51 pm »
Quote from: "Laurent"
And if you really want to do HTTP, there's a sf::Http class.


I looked at the sf::Http before the sockets, I only thought of using HTTP because it was "already there", I knew it should give SOME response.

Ill try what you suggested with the server. Thanks ;3

EDIT::

I think I get it now.

sf::Packet RegularPacket;

Makes an SFML packet, so it has its own header and what not which you can just send with .Send(whatever). You put data into that packet with RegularPacket << "somedata";
and the onReceive only works if your using sf::Packet to receive the SFML packet, yeah?

Also, reason I got confused with the .Connect problem was, on the next page there was a .cpp and it had
Code: [Select]

// Connect to the specified server
    if (!Client.Connect(Port, ServerAddress))
        return;

in it, so I mustve forgotten about the page before which had the if (Client.Connect(4567, "192.168.0.2") != sf::Socket::Done)

I mustve also missed this part of the conclusion:
Quote

It is important to remember that SFML packets use their own endianess and structure, so you cannot use them to communicate with servers that are not using them. To send raw data, HTTP / FTP requests, or whatever not built with SFML, use arrays of bytes instead of SFML packets.


Funny how someone elses input, even if youve been over it several times, makes it clearer.

9
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