Hi everyone,
I wrote a chat with the sfml network package using an additional thread (so I have 1 for sending and one for receiving).
I tested it and there are still some problems:
When using localhost or my local ip i can chat with myself without a problem.
When trying to chat between my pc and my laptop or between my pc and the pc of a friend who is on local lan it is only partially working:
On my pc everything is working.
On the other pcs when starting it prints
error connecting
error sending
When I send from my pc, the other pcs can receive it, but the other pcs cant send themselves, when they try it prints
error sending
Note: I'm printing this messages myself (see below)
My code is this:
int main(void)
{
std::string ipStr;
std::cout << "ip eingeben: ";
std::cin >> ipStr;
std::cout << std::endl;
sf::IPAddress address = ipStr;
if (!address.IsValid())
{
std::cerr << "invalid address" << std::endl;
}
SendeThread thread(address);
thread.Launch();
sf::SocketTCP Listener;
if (!Listener.Listen(4567))
{
std::cerr << "error listening" <<std::endl;
}
sf::SocketTCP Client;
if (Listener.Accept(Client, &address) != sf::Socket::Done)
{
std::cerr <<"error accepting" <<std::endl;
}
std::string line;
while(true)
{
sf::Packet toReceive;
Client.Receive(toReceive);
if(!(toReceive >> line))
{
std::cerr <<"error receiving" <<std::endl;
}
std::cout << "received: " << line << std::endl;
if(line == "quit")
{
break;
}
}
std::cout << "finished" << std::endl;
std::cin.peek();
return EXIT_SUCCESS;
}
void SendeThread::Run()
{
sf::SocketTCP Client;
if (Client.Connect(4567, myAddress) != sf::Socket::Done)
{
std::cerr <<"error connecting" <<std::endl;
}
while(std::cin)
{
sf::Packet toSend;
std::string line;
getline(std::cin, line);
toSend << line;
if (Client.Send(toSend) != sf::Socket::Done)
{
std::cerr <<"error sending" <<std::endl;
}
if(line == "quit")
{
return;
}
}
}
Please help me :-)
Is it a problem in the code, or just something with firewall or so?
I turned off firewalls and it didn't help, what else could it be?
Many thanks in advance!