1 Replies - 848 Views - Last Post: 04 December 2012 - 06:47 PM Rate Topic: -----

#1 Nano511  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 145
  • Joined: 07-October 12

simple SFML UDP client/server cannot send packets

Posted 04 December 2012 - 05:06 PM

The expected behavior is for the client to send a packet containing an ID, x, and y value and for the server to receive the packet and print out the x and y. At the moment, the client just can't send anything.

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 )
		{
...



Is This A Good Question/Topic? 0
  • +

Replies To: simple SFML UDP client/server cannot send packets

#2 Nano511  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 145
  • Joined: 07-October 12

Re: simple SFML UDP client/server cannot send packets

Posted 04 December 2012 - 06:47 PM

Could the problem be that the client and server are not being timed right? The client sends every 30 milliseconds and the server receives every 10 milleseconds and the dont start at the same time.. so is it possible that they are never lined up correctly? I am new to networking and not sure how to solve this problem.

Also, sometimes the client is able to send one message, but cannot successfully send any after that.

This post has been edited by Nano511: 04 December 2012 - 06:50 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1