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

Author Topic: Problem with sf::UdpSocket and sf::Packet  (Read 2112 times)

0 Members and 1 Guest are viewing this topic.

Brodal

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Problem with sf::UdpSocket and sf::Packet
« on: February 22, 2013, 11:14:29 pm »
For some reason i get wierd symbol on my small testprogram that waits for messages from my client. I'm trying to send sf::int32 value through a UdpSocket but on the serverside when i print the received message all that is being printed is weird symbols like smilies and such. What i tried was i took the sf::TcpSocket example that was in the documents and i just switched Tcp socket for Udp socket there. But for some reason I'm just getting weird data.

//Client

        m_socket = new sf::UdpSocket();
        m_socket->bind(3001);
        sf::IpAddress address;
        address = address.getLocalAddress();
        //std::string message = "Hello there you server there!";
        sf::Packet message;
        sf::Int32 param1 = 10;
        sf::Int32 param2 = 20;
        sf::Int32 param3 = 40;
        message << param1 << param2 << param3;


        m_socket->send(message, address, 3000);

//Server
m_udpSocket.bind(3000);

while(true)
        {
                std::cout << "WAITING FOR MESSAGE" << std::endl;

                sf::IpAddress sender;
                unsigned short port;
                sf::Packet receivedMessage;
                m_udpSocket.receive(receivedMessage, sender, port);
               
                sf::Int32 a, b, c;
                if (receivedMessage >> a >> b >> c)
                        std::cout << sender.toString() << " said: " << a << b << c << std::endl;
        };
}

What am I doing wrong? been searching on the forum but can't find a solution to this here problem..
« Last Edit: February 23, 2013, 09:37:57 am by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problem with sf::UdpSocket and sf::Packet
« Reply #1 on: February 23, 2013, 09:42:50 am »
Can you post the same thing, but as a complete example, so that we are 100% sure that the hidden code is not the cause of the problem?

Can you post the console output too?
Laurent Gomila - SFML developer

Brodal

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: Problem with sf::UdpSocket and sf::Packet
« Reply #2 on: February 23, 2013, 12:51:22 pm »
I managed to fix it, I don't know how but somehow it was fixed. Took quite some time but was probably just something that i overlooked. Thanks for the reply and sorry for the unnecessary post :)