1
Network / Data sent over UDP gives me strange ports
« on: March 15, 2011, 12:08:23 am »
Hi!
SocketUPD.Receive() gives me really strange ports. Since I both send data to port 6000 and bind the socket to port 6000, shouldn't the ReceivedPort variable be set to 6000 after the Receive method?
Here's the code:
sender.cpp
receiver.cpp
Output when ran three times:
This is just a test program, since I'm pretty much just starting programming with SFML. Thanks in advance!
SocketUPD.Receive() gives me really strange ports. Since I both send data to port 6000 and bind the socket to port 6000, shouldn't the ReceivedPort variable be set to 6000 after the Receive method?
Here's the code:
sender.cpp
Code: [Select]
#include "SFML/Network.hpp"
#include <iostream>
int main()
{
sf::IPAddress Address("127.0.0.1");
sf::SocketUDP Socket;
char SendMessage[] = "Yo! :P";
char ReceivedMessage[128];
std::size_t Received;
sf::IPAddress Sender;
unsigned short Port = 6000;
if(Socket.Send(SendMessage, 6, Address, Port) != sf::Socket::Done)
std::cout << "ERROR: Cannot send data";
return 0;
}
receiver.cpp
Code: [Select]
#include <SFML/Network.hpp>
#include <iostream>
int main()
{
sf::IPAddress Address("193.11.222.117");
sf::SocketUDP Socket;
unsigned short Port = 6000;
unsigned short ReceivedPort;
char ReceivedMessage[128];
std::size_t Received;
sf::IPAddress Sender;
Socket.Bind(Port);
Socket.Receive(ReceivedMessage, sizeof(ReceivedMessage), Received, Sender, ReceivedPort);
std::cout << Sender << ":" << ReceivedPort << std::endl;
std::cout << ReceivedMessage << std::endl;
return 0;
}
Output when ran three times:
Code: [Select]
127.0.0.1:59975
Yo! :P
127.0.0.1:38462
Yo! :P
126.0.0.1:35934
Yo! :P
This is just a test program, since I'm pretty much just starting programming with SFML. Thanks in advance!