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

Pages: [1]
1
Network / Re: Thread & Multiplayer
« on: November 19, 2012, 11:15:31 pm »
Edit2:

Ok, figured it out... somehow this line (in my constructor..)

clientSocket.setBlocking(false);

made it somehow connect before i even called the clientSocket.connect function... well well who would have guessed :D

2
Network / Re: Thread & Multiplayer
« on: November 19, 2012, 09:35:08 pm »
Ok, i dont know what else to post you tbh, this is where its never connecting...

Host.cpp

void Host::Listen()
{

        sf::TcpListener Listener;
        sf::IpAddress MyIP;

        Listener.listen(1234);
        cout << "Local: " << MyIP.getLocalAddress().toString() << "   ::   Public: " << MyIP.getPublicAddress().toString() << endl;

        quit = false;

        while (!quit)
        {
       
                sf::Packet send;
                string s;

                sf::TcpSocket *client = new sf::TcpSocket;
                cout << "Waiting for connection.." << endl;
       
                Listener.accept(*client);
                clients.push_back(client);
               
        }

}

void Host::Start()
{

        lthread = new sf::Thread(&Host::Listen, this);
        lthread->launch();

        Client client("127.0.0.1");
        client.Start();


}


Client.cpp

bool Client::Connect(string IP)
{

        bool connected = false;

        if ((clientSocket.connect(IP, 1234) == sf::Socket::Done)) /// This here NEVER connects... dont know why
        {
                cout << "Connected" << endl;
                connected = true;
        }
        if (connected == false)
        {
                cout << "Failed.." << endl;
                Connect(IP);
        }

        return connected;

}

void Client::Start()
{


        if (MyIP == "")
        {
                cout << "What IP?" << endl;
                cin >> MyIP;
        }

        Connect(MyIP);

}

3
Network / Re: Thread & Multiplayer
« on: November 19, 2012, 06:22:57 pm »
There is not much more code as posted above, what else you want to know? Im currently at my cellphone so my writing abilities are reduced ;)

It creates the thread, launches it and then the starterprocess wants to connect right afte...

4
Network / [Solved] Thread & Multiplayer
« on: November 19, 2012, 03:57:52 pm »
Hi there,


Im trying to connect to localhost with the Listening part running in a seperate thread... but it wont connect... and i dont know why :/

I tried many differend setting for IP, like "127.0.0.1" or "192.168.1.34" (Thats my local IP) but it wont connect..


The Idea behind is that i wanted to create a small game for multiple users, and one of them is the Host and he listens so users can connect...


My thought was that the connect is "too fast" so i put it into a loop so he connects over and over when he fails, but he never get the connection even then :/

        lthread = new sf::Thread(&Host::Listen, this);
        lthread->launch();
 

void Host::Listen()
{

        sf::TcpListener Listener;
        Listener.listen(1234);

        quit = false;

        while (!quit)
        {
       
                sf::TcpSocket *client = new sf::TcpSocket;
                Listener.accept(*client);
               
        }

}

if ((clientSocket.connect("127.0.0.1", 1234) == sf::Socket::Done))
        {
                connected = true;
        }
 

Pages: [1]