When I run this code on myself, it works fine, but when I run it on two computers and try to connect to each other, both can send but only one can receive, what's wrong? it's not a problem with the router/firewalls, I've set it up properly and it shouldn't affect the LAN anyway.
sf::IpAddress ip;
unsigned short int port = 2222;
void client()
{
sf::TcpSocket clientSocket;
sf::Packet clientPacket;
clientSocket.connect(ip, port);
while (true)
{
std::string send;
std::getline(std::cin, send);
clientPacket << send;
clientSocket.send(clientPacket);
clientPacket.clear();
}
}
void server()
{
sf::TcpListener listener;
sf::TcpSocket serverSocket;
sf::Packet serverPacket;
listener.listen(port);
listener.accept(serverSocket);
while (true)
{
std::string receive;
serverSocket.receive(serverPacket);
serverPacket >> receive;
std::cout << receive << "[received]" << std::endl;
serverPacket.clear();
}
}
int main()
{
std::cin >> ip;
std::cin.clear();
std::cin.ignore();
sf::Thread cThread(client);
sf::Thread sThread(server);
cThread.launch();
sThread.launch();
}