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