Witam
Od niedawna korzystam z biblioteki Network od SFML.
Mój problem w moim obecnym programie jest taki, że strona serwera nie aktualizuje
nowych nadchodzących pakietów ze strony klienta tylko ten pierwszy, pomimo zastosowania pętli.
Obrazek: https://ibb.co/LrXHQvt
/*
<NETWORK APPLICATION>
*/
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
using namespace std;
int main()
{
srand(time(NULL));
string connectionType;
cout << "Choose the connection type: <s> to the server, <c> to the client" << endl;
cin >> connectionType;
//<--TIMER-->//
sf::Time appTimer;
sf::Clock appClock;
//<--SOCKETS-->//
sf::UdpSocket appSocket;
sf::IpAddress recipientIpAddress("192.168.0.100");
sf::IpAddress senderIpAddress("192.168.0.100");
sf::Packet socketPacket;
sf::Uint16 x = 2;
unsigned short socketPort = 5325565335885;
//<--SERWER-->//
if(connectionType == "s")
{
appSocket.bind(socketPort);
while(true)
{
appTimer = appClock.getElapsedTime();
if(appTimer.asSeconds() > 1.f)
{
appClock.restart();
appSocket.receive(socketPacket, senderIpAddress, socketPort);
socketPacket >> x;
cout << "SERWER: " << x << endl;
}
}
}
//<--CLIENT-->//
else if(connectionType == "c")
{
while(true)
{
appTimer = appClock.getElapsedTime();
if(appTimer.asSeconds() > 1.f)
{
appClock.restart();
x = rand()% 256;
cout << "CLIENT: " << x << endl;
socketPacket << x;
appSocket.send(socketPacket, senderIpAddress, socketPort);
}
}
}
//<--ERROR-->//
else
{
cout << "You've chosen the wrong menu option!";
}
return 0;
}