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 - JohnGreek

Pages: 1 2 [3]
31
Network / Problem with TCP server/client [v1.6]
« on: August 01, 2011, 05:53:27 pm »
Quote from: "Laurent"
Quote
i noticed that when i use connect if there is no connection possible it returns so the application terminates. So i wrap it in this loop to check if the connection is sucessfull step out and send data etc etc.

You're calling Connect twice per iteration, so the first one is always ignored. And you're looping while it returns Disconnected, but it could as well return Error or NotReady.

but even without the loop it returns.


I'm messing with networking for quite some time now, but i always end up in dead-ends and it's really annoying. I am working with Winsock too, very well documented but extremely complicated. SFML network is easier than Winsock but i don't really see light. The thing is that i am working with c++ for 4 years and never stuck into something for such a long time. I think i may need to look for a general network programming tutorial. If you have any tips they are welcome...  :?

32
Network / Problem with TCP server/client [v1.6]
« on: August 01, 2011, 05:01:39 pm »
i noticed that when i use connect if there is no connection possible it returns so the application terminates. So i wrap it in this loop to check if the connection is sucessfull step out and send data etc etc.

I don't really get your second tip. The caller get's random data? Since the server is in accept it should block until a client connects, so it should wait until the client connects. Indeed, when i connect it exits from accept but i get the random data.
I'm trying to learn SFML cause it's much more better than SDL(using SDL for about 2 years), the most important is the OO structure, not to mention the graphics manipulation. But i wish it had a bigger community..  :(

33
Network / Problem with TCP server/client [v1.6]
« on: August 01, 2011, 04:43:27 pm »
This is the server sc:
Code: [Select]
#include <SFML/System.hpp>
#include <SFML/Network.hpp>
#include <iostream>
#include <string>
#include <windows.h>

using namespace std;
using namespace sf;


class Server
{
    private:
        SocketTCP InSocket;
        SocketTCP OutSocket;
        unsigned short ClientPort;

        IPAddress ClientAddress;
        char RecievedData[10];
        size_t RecievedDataSize;

    public:
        Server();
        ~Server();

        void RecieveData()
        {
            InSocket.Receive( RecievedData, sizeof(RecievedData), RecievedDataSize);
        }
        string WaitConnections(int port);
        bool StartServer();
};


bool run = true;
Server *server= NULL;

Server::Server()
{
    InSocket.SetBlocking(true);
    OutSocket.SetBlocking(true);
}
Server::~Server()
{

}
string Server::WaitConnections(int port)
{
    if(!InSocket.Listen(port))
        return "ERROR";

    cout << "Waiting for connections on port " << port << endl;

    InSocket.Accept(OutSocket, &ClientAddress);
    cout << "Client connected: " << ClientAddress << endl;

    cout << "Connection established!" << endl;
}
bool Server::StartServer()
{
    RecieveData();

    cout << "Data from client: " << RecievedData << endl;

    cout << "ALL IS GOOD!" << endl;
}




int main()
{
    server= new Server();
    server->WaitConnections(1025);
    server->StartServer();
    system("pause");
}


And this is the client sc:

Code: [Select]
#include <SFML/System.hpp>
#include <SFML/Network.hpp>
#include <iostream>
#include <string>
#include <windows.h>

using namespace std;
using namespace sf;

class Client
{
    private:
        SocketTCP ClientSocket;
        unsigned short ServerPort;

        IPAddress ServerAddress;
        char ToSendData[10];

    public:
        Client();
        ~Client();

        void InitClient(string address, unsigned short port);
        bool StartClient();
};

bool run = true;
string server_address;
Client *client= NULL;



Client::Client()
{

}
Client::~Client()
{

}
void Client::InitClient(string address, unsigned short port)
{
    ServerAddress= address;

    ServerPort= port;
}
bool Client::StartClient()
{
    cout << "Connecting on server at address " << ServerAddress << endl;
    do
    {
        ClientSocket.Connect(ServerPort, ServerAddress);
    }
    while (ClientSocket.Connect(ServerPort, ServerAddress)== Socket::Disconnected );

    cout << "You have been connected to the server!" << endl;

    cout << "Enter the data to send to the server: ";
    cin >> ToSendData;

    ClientSocket.Send( ToSendData, sizeof(ToSendData) );
}



int main()
{
    client= new Client();
    client->InitClient("127.0.0.1", 1025);
    client->StartClient();
    system("pause");
}


If you have any question tell me.

34
Network / Problem with TCP server/client [v1.6]
« on: August 01, 2011, 03:52:29 pm »
i try with any port, it's the same.
OS is Win7 x32

35
Network / Problem with TCP server/client [v1.6]
« on: August 01, 2011, 03:07:56 pm »
Hello!
I'm using SFML network for a server/client system but i'm stuck in a very weird point. When i try to connect the client to localhost, even without the server open i get a connection(!) and when i open the server and i recieve data i get some system paths and hardware ids. ex my CPU data or a path to my gfx card panel from the socket. More detailed, the cases:

(1)
Server is offline
Client connects to localhost sucessfully like the server is online

(2)
Server is online
Client connects and before i manage to send data
Server recieves weird data from socket(supposed to be empty)
CPU hardware details and some system32 paths to some executables(!)


I tried using the tutorial code but it's not suitable since it expects the server to be online i need the opposite.
What really is the issue:

1. Client connects to localhost without the server online
2.Server recieves data from client when it's connected without the client to send anything


Any help is appreciated.
Thanks in advance.

36
System / Help with clock()
« on: September 13, 2009, 05:09:14 pm »
It works! :)
i thought that the "if" condition was considered an event.. lol
and about the clock you are right, it was incorrect placed in the loop.
It troubled me a hell lot but i made it thanks to you guys
thank you :D

Quote from: "Spidyy"
Reset() automaticaly at the creation. =p

I didn't knew that :o

37
System / Help with clock()
« on: September 13, 2009, 04:38:17 pm »
thanks for your replies, i replaced my code but still the application does a weird thing, instead of closing at > 3 it closes at random times(5,12 etc.) i'm kinda confused.

My code:
Code: [Select]


////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
////////////////////////////////////////////////////////////
int main()
{
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Clock Timer;
        sf::Event Event;
        while (App.GetEvent(Event))
        {

        if (Timer.GetElapsedTime() >= 3)
            App.Close();


        if (Event.Type == sf::Event::Closed)
            App.Close();
        }

        // Display window contents on screen
        App.Clear();
        App.Display();
    }

    return EXIT_SUCCESS;
}


I am a little sick too and my head hurts so the code might have some stupid mistakes, plz note them if you see any.

38
System / Help with clock()
« on: September 13, 2009, 01:19:47 am »
I'm sorry but i'm not at that stage to understand most of this code...
-I am newbie and i'd like to help me in a more "newbie" way
-what is "then" command??? never seen it before
-"Process" never seen it too...
-lol never seen a while loop with "-" instead of brakets

P.S i just reached "Sprites tutorial"...

39
System / Help with clock()
« on: September 13, 2009, 12:29:49 am »
Since i started learning SFML recently i wanted to "test" my self with a program(window) that simply closes after 3 seconds.
I spend many hours and even with help i can't get it done

Here's my code:

Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
sf::Clock Clock;

while (App.IsOpened())
{
sf::Event Event;

while (App.GetEvent(Event))
{
    int Time = Clock.GetElapsedTime();
    Clock.Reset();
        if (Time==3)
            App.Close();

    if (Event.Type == sf::Event::Closed)
        App.Close();
}


App.Clear();
App.Display();
}

return EXIT_SUCCESS;

}


My thoughts are:

Maybe sf::RenderWindow() doesn't accept to be closed through time...?
Maybe  Clock's functions are not correctly placed in the code?
Maybe it's all wrong...

Anybody can help???

40
General / SFML on Code::Blocks [linker error]
« on: September 11, 2009, 03:50:04 pm »
but that's the point, i did everything step-by-step on the tutorial for Code Blocks and still it's not working, i get the the same errors.
those errors mean the sfml-system library is not linked...
i just don't understand what i'm doing wrong :/

EDIT: i got it working, thx for your help

41
General / SFML on Code::Blocks [linker error]
« on: September 11, 2009, 01:56:54 pm »
thx for your fast reply :)
well, yeah you are right, devcpp is long ago abandoned...
so i downloaded code blocks and i configured it but i get the same errors like devcpp.
i made all the steps many times, added the includes and the library, but still no luck.

SS of the compiler

42
General / SFML on Code::Blocks [linker error]
« on: September 11, 2009, 11:50:21 am »
and how exactly i link to that?

43
General / SFML on Code::Blocks [linker error]
« on: September 11, 2009, 11:12:49 am »
Heya, this is my first post here and i'd like to say hi to everybody :D
now to the point:

I am using Dev C++ as IDE and when i try to compile the simplest window app(just using window.hpp) i keep getting those errors:
--------------------
 In function `main':
  [Linker error] undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
  [Linker error] undefined reference to `sf::Window::Window(sf::VideoMode, std::string const&, unsigned long, sf::WindowSettings const&)'
  [Linker error] undefined reference to `sf::Window::Display()'
  [Linker error] undefined reference to `sf::Window::~Window()'
  [Linker error] undefined reference to `sf::Window::~Window()'
  ld returned 1 exit status  
--------------------
I just don't understand why i get those link errors.
I did a small search and i found that those errors occur when i am using a function that is not inside the headers i include but i think everything is fine...
I have tried everything(look for other tutorials, rewrite the code a hundred times) but still nothing.
I am kinda newbie to libraries so i could use some help :P

Pages: 1 2 [3]
anything