Well, i have this problem. Hope somebody can help me.
Sender:
#include <SFML/Network.hpp>
#include <iostream>
int main()
{
sf::IPAddress Address("XXX.XXX.XXX.XX"); // My public IP
std::string ip = Address.ToString();
sf::SocketTCP *sock = new sf::SocketTCP;
sf::SocketTCP Listener;
Listener.Accept(*sock, &Address);
char toSend[] = "Hola, qué tal";
Listener.Listen(2000);
sock->Send(toSend, sizeof(toSend));
return 0;
}
Receiver:
#include <iostream>
#include <SFML/Network.hpp>
int main()
{
sf::IPAddress ip(sf::IPAddress::GetPublicAddress());
std::cout << "Mi IP es " << ip.ToString() << "." << std::endl;
sf::SocketTCP socket;
sf::SocketTCP socketEntrada;
std::size_t asdf;
socketEntrada.Connect(2000,"XXX.XXX.XXX.XX"); // My public IP
char recibidor[] = "asdasdasdasdfafgufbrfsifhbvrufbwufbwuvwufebwfnwjfvwuebfwhlbfvewf";
if (!socket.Listen(2000)) {
std::cout << "No se puede escuchar el puerto 2000." << std::endl;
return 1;
}
while (!socket.Accept(socketEntrada, NULL));
std::cout << "Se a conectado al puerto 2000." << std::endl;
socketEntrada.Receive(recibidor, sizeof(recibidor), asdf);
std::cout << recibidor << std::endl;
r eturn 0;
}
I run first the reciever, then in another terminal the sender, and the sender oututs this:
"Failed to bind socket to port 2000".
Why is this happening?
Thank you, greetings.
EDIT:I changed the ort to 1984, and now the sender runs, but nothing happens, it just ends in 1 milisecond (?), and the reciever just stay like "nikolov@rettask:~/Escritorio$ ./B
Mi IP es 201.141.136.35."