Here is the code i think is relevant.
In the main of the client code
//Send the position to the server
if(clock.getElapsedTime() > sf::milliseconds(30))
{
clock.restart();
packet.clear();
packet << ID << ball._position.x << ball._position.y;
if( socket.send(packet, serverAddress, 55002) != sf::Socket::Done)
std::cout<<"Error sending packet" << std::endl;
}
In the Receive thread of the Server Code
if(socket.bind(55002) != sf::Socket::Done)
std::cout<< "Unable to bind UDP socket: 55002" << std::endl;
...
for(;;sf::sleep(sf::milliseconds(10)))
{
int rec = socket.receive(packet,senderIP,senderPort);
if( rec == sf::Socket::Done )
{
...

New Topic/Question
Reply



MultiQuote



|