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

Author Topic: UDP simple functions  (Read 2140 times)

0 Members and 1 Guest are viewing this topic.

pickumater

  • Newbie
  • *
  • Posts: 4
    • View Profile
UDP simple functions
« on: August 17, 2013, 02:25:22 am »
Hello, newbie here, I'm having a problem with udp socket receiving a packet.
What exactly is wrong with these 2 functions? The packet is sent, but never received
Fucntion for receiving

bool SprejmiTest(unsigned short port)
{
       
        sf::Packet PacketTest2;
        sf::IpAddress IpEna;
        unsigned short Port;
        std::string Beseda;



        sf::UdpSocket SocketServerTest;
        SocketServerTest.setBlocking(0);
        SocketServerTest.bind(port);
        if(SocketServerTest.receive(PacketTest2,IpEna,Port)==sf::Socket::Done){
        PacketTest2>>Beseda;
        std::cout<<Beseda<<std::endl;
        std::cout<<"Testni paket je sprejet"<<std::endl;
        return true;}
          else
             return false;


}
       

Function for sending

bool PosljiTest(sf::IpAddress IpTest,unsigned short PortTest)
{

        std::string Beseda="Zivjo";
        sf::Packet PacketTest;
        sf::UdpSocket SocketTest;
        SocketTest.setBlocking(0);
       
        PacketTest<<Beseda;
        if(SocketTest.send(PacketTest,IpTest,PortTest)!=sf::Socket::Done){std::cout<<"Paket ni bil poslan";return false;}
        std::cout<<"Paket poslan"<<std::endl;
        return true;

}

Thank you!
« Last Edit: August 17, 2013, 02:29:16 am by pickumater »

io

  • Jr. Member
  • **
  • Posts: 52
  • z/OS by day, SFML by night
    • View Profile
Re: UDP simple functions
« Reply #1 on: August 17, 2013, 06:59:14 am »
Doesn't SocketServerTest.setBlocking(0); set you in non-blocking mode meaning your receive function always returns immediately?

pickumater

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: UDP simple functions
« Reply #2 on: August 17, 2013, 10:41:38 am »
I set it to 1 and it worked, thank you very much! : )