Ok, thank you! Now it's working. ...but if i try to launch the client program a second time nothig is sended to the server...why?
Networking is a pain!
Here i post the code again with the tag cpp as you suggested:
Server side:#include <iostream>
#include <SFML/Network.hpp>
int main(int argc, char* argv[])
{
// ----- The server -----
// Create a listener to wait for incoming connections on port 55001
sf::TcpListener listener;
listener.listen(5001);
if (listener.listen(5001) != sf::Socket::Done){
// error...
}
// Wait for a connection
sf::TcpSocket client;
if (listener.accept(client) != sf::Socket::Done)
{
// error...
}
std::cout << "New client connected: " << client.getRemoteAddress() << std::endl;
// Receive a message from the client
while(true){
sf::Packet packet;
client.receive(packet);
sf::Uint16 x;
std::string s;
double d;
if (packet >> x && packet >> s && packet >> d) {
std::cout << "x: " << x << ", s: " << s << ", d: " << d << std::endl;
}
}
return 0;
}
Client side:#include <iostream>
#include <SFML/Network.hpp>
int main(int argc, char* argv[])
{
// ----- The client -----
sf::TcpSocket socket;
sf::Socket::Status status = socket.connect("192.168.1.71", 5001);
if (status != sf::Socket::Done){
// error...
}
sf::Uint16 x = 12;
std::string s = "hello2";
double d = 0.7;
sf::Packet packet;
packet << x << s << d;
socket.send(packet);
return 0;
}