Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Packet Send and Receive  (Read 25320 times)

0 Members and 1 Guest are viewing this topic.

lohr

  • Newbie
  • *
  • Posts: 15
    • View Profile
Packet Send and Receive
« on: June 30, 2008, 11:38:57 am »
Hello,

I want to send and receive a packet with the following structure:

Code: [Select]
struct Position
{
    int     x;
    int y;
int rot;
};


now thats my server Init:

Code: [Select]
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:

Code: [Select]
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:

Code: [Select]
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:

Code: [Select]
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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Packet Send and Receive
« Reply #1 on: June 30, 2008, 11:43:19 am »
Quote
but it isnt working...

Can you give more details please ? ;)
Laurent Gomila - SFML developer

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Packet Send and Receive
« Reply #2 on: June 30, 2008, 12:05:07 pm »
Well, you are sending the packet twice... that may be a problem.

lohr

  • Newbie
  • *
  • Posts: 15
    • View Profile
Packet Send and Receive
« Reply #3 on: June 30, 2008, 12:24:19 pm »
Quote from: "Laurent"
Quote
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.

Quote
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.

lohr

  • Newbie
  • *
  • Posts: 15
    • View Profile
Packet Send and Receive
« Reply #4 on: June 30, 2008, 02:08:45 pm »
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?