Hi. I have a question more related to network functionality rather than to programming.
Code below is responsible for sending packet:
std::string ipString;
sf::UdpSocket socket;
sf::Packet packet;
unsigned short port;
std::cout << "Set recipient IP: ";
std::cin >> ipString;
std::cout << "Set recipient port: ";
std::cin >> port;
sf::IpAddress ipAddress(ipString);
socket.send(packet, ipAddress, port);
As a sender I have to set IP address of recipient and recipient's port.
And this code is responsible for receiving packet:
unsigned short port;
sf::UdpSocket socket;
sf::IpAddress ipAddress;
sf::Packet packet;
std::cout << "Set server port: ";
std::cin >> port;
socket.setBlocking(false);
socket.bind(port);
while(true)
{
if(socket.receive(packet, ipAddress, port) == sf::Socket::Done)
{
std::cout << "IP Address: " << ipAddress << " port: " << port << std::endl;
}
}
After receiving a packet, variables ipAddress and port are filled with sender's IP and port number.
So let's say, I want to set server at port 4096 and try to send packet from client. So as a client I set server's IP and port number. Everything is ok, my packet went to server. But here is my question. Server's output is good as far as IP address is concerned, but port number is different than 4096. I presume that it should be like that and everything is good, but I don't understand why client's port is different than 4096. I'm looking forward your answer.