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.