SFML community forums
Help => Network => Topic started by: lohr on June 30, 2008, 11:38:57 am
-
Hello,
I want to send and receive a packet with the following structure:
struct Position
{
int x;
int y;
int rot;
};
now thats my server Init:
sf::SocketTCP Server;
if (!Server.Listen(1000))
return EXIT_FAILURE;
sf::IPAddress ClientAddress;
sf::SocketTCP Client;
Server.Accept(Client, &ClientAddress);
sf::Packet RegularPacket;
Position P;
and thats my client Init:
sf::IPAddress ServerAddress = sf::IPAddress::GetLocalAddress();
sf::SocketTCP Client;
if (!Client.Connect(1000, ServerAddress))
return EXIT_FAILURE;
sf::Packet RegularPacket;
Position P;
Here is the Receive Part of the Server:
if (Client.Receive(RegularPacket) != sf::Socket::Done)
return EXIT_FAILURE;
if (RegularPacket >> P)
{
s_auto.SetPosition(P.x,P.y);
s_auto.SetRotation(P.rot);
}
Here is the Send Part of the Client:
P.x = pos.x;
P.y = pos.x;
P.rot = rot;
if (RegularPacket << P)
{
if (Client.Send(RegularPacket) != sf::Socket::Done)
return EXIT_FAILURE;
}
if (Client.Send(RegularPacket) != sf::Socket::Done)
return EXIT_FAILURE;
Its a litte Car Racing game where i am trying to send the position of the client car to the server, but it isnt working...
The Connection is established betweeen them.
Do you find anything wrong?
Best regards,
lohr
-
but it isnt working...
Can you give more details please ? ;)
-
Well, you are sending the packet twice... that may be a problem.
-
but it isnt working...
Can you give more details please ? ;)
Okay sorry ^^
The first pos and rot info that i am sending always is received by the server, all others after that get lost.
Well, you are sending the packet twice... that may be a problem.
Hm i tried it with one sending operation as well and it didnĀ“t work.
-
So it is working...
I forgot to run the Clear() Method for the RegularPacket ^^
Do you have any tips on the fixing of latency problems?