Hello, It's my first time working with Network in SFML
In general, I'm trying to send OpenCV cv::Mat by UDP Package, but for now, I'm just trying to get a constant stream of data.
Unfortunately, there's something wrong with my program - or I'm don't quite understand something :<
Sending side (to minimalize errors, I do not use a loop and just execute the sending program a few times):
{
sf::IpAddress recipient = "10.3.189.55";
unsigned short port = 54000;
sf::UdpSocket socket;
if (socket.bind(54000) != sf::Socket::Done)
{
return -1;
}
char data[100];
sprintf(data, "Package #");
if (socket.send(data, 10, recipient, port) != sf::Socket::Done)
{
return -2;
}
return 0;
}
And receiving side :
{
sf::UdpSocket socket;
unsigned short port = 54000;
if (socket.bind(54000) != sf::Socket::Done)
{
return -1;
}
sf::IpAddress sender;
std::size_t received;
while (true)
{
char data[100] = "";
if (socket.receive(data, 100, received, sender, port) != sf::Socket::Done)
{
std::cout << "Error while reading\n";
continue;
}
std::cout << "Received " << received << " bytes from " << sender << " on port " << port << "\n"
<< data << std::endl;
}
return 0;
}
After exactly 5 messages, receiving stop and resume only after some time (~minute or two) - which is obviously not good, I have no idea what I'm doing wrong
PS: One more question. Do I understand correctly that if I use sf::Packet then I don't need to be concerned about sf::UdpSocket::MaxDatagramSize?