2 Replies - 1252 Views - Last Post: 08 December 2012 - 11:35 PM Rate Topic: -----

#1 DrHaximus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 08-December 12

SFML networking - packets issue

Posted 08 December 2012 - 08:10 PM

Hi.
I have a server and a client for my OpenGL game, and I want to be able to get a packet containing floats from the server for my gluLookAt function on the client side.

The problem is, after sending and receiving around 10 valid packets with correct information (the amount varies), the client will freeze. The function to retrieve the information from the server is run every frame - BUT, it doesn't matter how many frames per second the program gets.

I'm working with UDP, by the way.

The information retrieving function on the client:

void updateCamera() {
	sendToServer(sf::Uint16(4));
	sf::Packet output = getServerResponse();
	sf::Uint16 camtype;
	output >> camtype;
	float camx;
	float camupangle;
	float camz;
	float camlx;
	float camheight;
	float camlz;
	output >> camx >> camupangle >> camz
		>> camlx >> camheight >> camlz;
	if (camtype != 4) {
		return;
	}
	gluLookAt(	camx, camupangle, camz,
			camx+camlx, camheight,  camz+camlz,
			0.0f, 1.0f,  0.0f);
	std::cout<<"Set position\n";
}



On the server to send it to the client:

else if (type == 4) {
			getPlayer(sender.toString()).init();
			sf::Packet tosend;
			sf::Uint16 newtype = 4;
			tosend << newtype;
			float camx = getPlayer(sender.toString()).x;
			float camupangle = getPlayer(sender.toString()).upAngle;
			float camz = getPlayer(sender.toString()).z;
			float camlx = getPlayer(sender.toString()).lx;
			float camheight = getPlayer(sender.toString()).height;
			float camlz = getPlayer(sender.toString()).lz;
			tosend << camx << camupangle <<
				camz << camlx << camheight <<
				camlz;
			serverSocket.send(tosend,sender,senderPort);
			std::cout<<"Got camera request.\n";
		}



Remember, this is valid code and I WILL get around 10 CORRECT packets.

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: SFML networking - packets issue

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: SFML networking - packets issue

Posted 08 December 2012 - 09:15 PM

Where is the receive code? What is the size of the packets that you are sending? Describe more about the crash.
Was This Post Helpful? 0
  • +
  • -

#3 DrHaximus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 08-December 12

Re: SFML networking - packets issue

Posted 08 December 2012 - 11:35 PM

View PostButchDean, on 08 December 2012 - 09:15 PM, said:

Where is the receive code? What is the size of the packets that you are sending? Describe more about the crash.


Ok.

int main() {
	init();
	serverSocket.bind(3725);
	serverSocket.setBlocking(false);
	while(true){
		sf::Packet received;
		sf::IpAddress sender;
		unsigned short senderPort;
		serverSocket.receive(received,sender,senderPort);
		sf::Uint16 type;
		received >> type;
		if (type == 4) {
			getPlayer(sender.toString()).init();
			sf::Packet tosend;
			sf::Uint16 newtype = 4;
			tosend << newtype;
			Player target = getPlayer(sender.toString());
			float camx = target.x;
			float camupangle = target.upAngle;
			float camz = target.z;
			float camlx = target.lx;
			float camheight = target.height;
			float camlz = target.lz;
			tosend << camx << camupangle <<
				camz << camlx << camheight <<
				camlz;
			serverSocket.send(tosend,sender,senderPort);
			std::cout<<"Got camera request.\n";
		}
}



I explained everything about the crash. After a few packets it simply stops, and I am unable to move the window, select it, close it, whatever.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1