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

Pages: [1]
1
Network / Re: Socket try connect multiple times
« on: May 08, 2015, 01:58:50 pm »
Okay, so in fact I have another problem but related I guess.

I have my udp socket and I can check and find the server on the network and it works fine. But I can't connect with TCP to the server after that. The clients seems to be able to connect but the server does not react. If I don't send data with UDP before, I can connect to the tcplistener, but otherwise not. The TCP port and the UDP are different.

Here's the server side function.
    if(selector.wait())
    {
        if(selector.isReady(listener))  // If there's a pending connection
        {
           // SFML DOC LIKE
        }

        if(selector.isReady(udp_socket))
        {
            sf::Socket::Status st = udp_socket.receive(pack,sender_ip,sender_port)
            // if what I received is correct I answer something to the client who sent the pack
            udp_socket.send(pack,sender_ip,sender_port);
         }
}

And here is where I try to connect with the client.

 
    for(int i = first_addr; i < last_addr;i++)
             udp_socket.send(pack,test,udp_port);  // Sent on every adress between first and last (test is a string which contains the full adress)
   
    udp_socket.bind(udp_port);
    udp_socket.setBlocking(false);
    udp_socket.receive(pack,server,server_port);
    udp_socket.unbind();
 

After that, I get the adress of the server who sent the pack and I try to connect to with the TCP port (which is not the same as the UDP one).
I also tested the TCP connection directly on the server with a simple program and it works.

I don't get why it does this.
Edit: Removed a lot of not related code

2
Network / Re: Socket try connect multiple times
« on: May 04, 2015, 02:02:00 pm »
Ok so, I understood my mistake. I was trying to do some kind of broadcasting (because I wanted to check if there was a server on the network), but with a TCP Socket. I now use the UDP Socket to do this and it works fine.

3
Network / Re: Socket try connect multiple times
« on: April 27, 2015, 03:48:39 pm »
I forgot to mention that the socket is non-blocking and I have a few things more after that.

4
Network / Socket try connect multiple times
« on: April 27, 2015, 11:22:22 am »
Hello,

I have a project where I need to check in the network if there's already a server. I'm trying to connect a socket and the first time I call the connect method the socket is able to connect but otherwise it can't. Like the socket can only connect if the adress of the server is the first one to be tested.

for(int i = first ; i <= last; i++)
{ // net_id -> something like "192.168.140", first and last define the set of adresses
    test = net_id;
    test.append(".");
    test.append(std::to_string(i));  // 192.168.140.1, 192.168.140.2, ...
    sf::Socket::Status status = s_test.connect(test,port);
}

5
Network / Re: Crash on selector.wait() with a std::thread
« on: March 10, 2015, 08:34:49 am »
Yeah I added it before in the code. Thanks for your help I guess i'll learn more about the C++ the threads and using the SFML before trying to do a correct multi threaded server.

6
Network / Re: Crash on selector.wait() with a std::thread
« on: March 09, 2015, 02:57:36 pm »
Sorry I wanted to post the full code before, but I had a lot of things to do this week.

So here's the code of the client :
int port = 48000;
sf::TcpSocket socket;
sf::Socket::Status status = socket.connect("127.0.0.1",port);

if(status != sf::Socket::Done)
        std::cout << "Unable to connect on port " << port << std::endl;
else
{
        std::cout << "Connected to the server on port " << port << std::endl;
        sf::Packet pack;
        std::cin.get();
        pack << "aaaaaa";

        if (socket.send(pack) != sf::Socket::Done)
            std::cout << "Unable to send the packet." << std::endl;
        else
            std::cout << "Packet send." << std::endl;

}

And here is the full code of the server (in the thread) :
listener.listen(this->port);
cout << "started on the port " << port << endl;
while(true)
{
         if (selector.wait())
        {
            // Test the listener
            if (selector.isReady(listener))
            {
                cout << "Client connected." << endl;
                // The listener is ready: there is a pending connection
                sf::TcpSocket* client = new sf::TcpSocket;
                if (listener.accept(*client) == sf::Socket::Done)
                {
                    // Add the new client to the selector so that we will
                    // be notified when he sends something
                    selector.add(*client);
                    //emit New_Client(client);
                }
                else
                {
                    // Error, we won't get a new connection, delete the socket
                    delete client;
                }
            }
        }
        else
        {
            // The listener socket is not ready, test all other sockets (the clients)
            for (std::list<sf::TcpSocket*>::iterator it = clients.begin(); it != clients.end(); ++it)
            {
                sf::TcpSocket& client = **it;
                if (selector.isReady(client))
                {
                    // The client has sent some data, we can receive it
                    sf::Packet packet;
                    if (client.receive(packet) == sf::Socket::Done)
                    {
                        string data;
                        packet >> data;
                        cout << "Received : " << data << endl;
                    }
                }
            }
        }
    }

The clients tells me he's connected on the server and was able to send the packet but it's like I get no connection and no data on the server.

7
Network / Re: Crash on selector.wait() with a std::thread
« on: March 03, 2015, 03:16:42 pm »
Thanks it was this. I don't know how I couldn't see that.
I found another problem. The clients seems to connect and send data to the server but the server does not receive anything.

8
Network / Crash on selector.wait() with a std::thread
« on: March 03, 2015, 02:34:51 pm »
Hello,

I'm learning to use the threads with the SFML network.
I have a thread (std) for the server on which it listens all the time but I always get the error segementation default on the selector.wait.

My class in which I initialize my thread :

void Application::Start()
{
    Network net1(this->port);
    std::thread server_thread(&Network::Run,&net1);
    server_thread.detach();
}

The run fonction of the network class for the server :

void Network::Run()
{
    listener.listen(this->port);
    while(true)
    {
        if (selector.wait())                          // crash here
        {
            // Test the listener
            if (selector.isReady(listener))
            {
                cout << "Client connected." << endl;
                ...
            }
        }
     }
}

Thanks for your help.

9
General / Re: Problems to use the lib with QtCreator on Ubuntu
« on: November 20, 2014, 08:59:41 pm »
Ok so I resintalled everything including cmake gcc compilator, etc.. and build it myself. Thanks for your help.

10
General / Re: Problems to use the lib with QtCreator on Ubuntu
« on: November 19, 2014, 11:57:59 pm »
Im on Ubuntu 14.10 but as I said when I install it with the command apt-get install I can't use it, it keeps giving me the error "undefined reference".

11
General / [Resolved] Problems to use the lib with QtCreator on Ubuntu
« on: November 18, 2014, 11:09:49 am »
Hi,
I'm trying to include the lib on QtCreator but it doesn't work. If I install SFML with sudo apt-get install libsfml-dev I get the errors "undefined reference to...". If I install it "manually" I get the errors "cannot find lsfml-audio-d, lsfm-network-d,...". Here is my .pro file
QT       += core
QT       -= gui
TARGET = test_sfml
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app

SOURCES += main.cpp

LIBS += -L"/home/ludo/SFML/lib"
CONFIG(release, debug|release): LIBS += -lsfml-audio -lsfml-graphics -lsfml-network -lsfml-window -lsfml-system
CONFIG(debug, debug|release): LIBS += -lsfml-audio-d -lsfml-graphics-d -lsfml-network-d -lsfml-window-d -lsfml-system-d
INCLUDEPATH += "/home/ludo/SFML/include"
DEPENDPATH += "/home/ludo/SFML/include"
 
If anyone could help me that would be great.

Pages: [1]
anything