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

Author Topic: Socket.send fails on Windows  (Read 2051 times)

0 Members and 1 Guest are viewing this topic.

virus989898

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Socket.send fails on Windows
« on: August 15, 2014, 02:06:44 pm »
Hi,
I finished program for controlling my quadcopter for linux machine and it works.
#include <SFML/Network.hpp>
#include <SFML/Window.hpp>
#include <iostream>

sf::UdpSocket socket;

sf::Packet paczka;
int id = 1; // 1 -> pc, 2 -> dron

sf::IpAddress odbiorca = "localhost";
unsigned short port = 54321;

#define rcthr z
#define roll x
#define pitch y
#define yaw r
#define high v

int old_roll = 0;
int old_rcthr = 0;
int old_pitch = 0;
int old_yaw = 0;
int old_high = 0;

void wypisywanie(int x, int y, int z, int r)
{
        std::cout << "\nroll(x): " << x << "  pitch(y): " << y << "  rcthr(z): " << z << "  yaw(r): " << r;
}



void push() {
        if (socket.send(paczka, odbiorca, port) != sf::Socket::Done)
        {
                std::cout << "ERROR\n";
        }
}

int main()
{
        int sygnal = 2;
        //odbiorca = "localhost";
        sf::Joystick::update();
        int button = sf::Joystick::getButtonCount(0);
        std::cout << "znalazlem" << button << "przyciskow";
        while (true)
        {
                sf::Joystick::update();

                int roll = sf::Joystick::getAxisPosition(0, sf::Joystick::X);
                int pitch = sf::Joystick::getAxisPosition(0, sf::Joystick::Y);
                int rcthr = sf::Joystick::getAxisPosition(0, sf::Joystick::Z);
                int yaw = sf::Joystick::getAxisPosition(0, sf::Joystick::R);
                int high = sf::Joystick::getAxisPosition(0, sf::Joystick::PovY);
                yaw *= -1;
                rcthr *= -1;
                rcthr += 100;
                //    wypisywanie(roll,pitch, rcthr, yaw, high);

                //      if ( (roll != old_roll) or (pitch != old_pitch) or (rcthr != old_rcthr) or (yaw != old_yaw) or (high != old_high)  ) {

                wypisywanie(roll, pitch, rcthr, yaw);
                paczka.clear();
                paczka << sygnal << id << roll << pitch << rcthr << yaw;
                push();

                sf::Time t = sf::seconds(0.05f);
                sf::sleep(t);  
                //      }


        }
        //std::cout << sf::Joystick::Count;


        return 0;
}
 
But when I tried to compile it on Windows machine I allways get ERROR after every end of line printed by "push" function. I dont know if there is a problem with my Visual Studio 2013 configuration or Windows 8 safty stuff (I've got Windows firewall and antivirus off). Do You get the same error with this code?

Thanks in advance!

virus989898

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Socket.send fails on Windows
« Reply #1 on: August 15, 2014, 03:06:41 pm »
OK, I figured out that localhost is not working on Win8.1, so I put 127.0.0.1 instead.

SOLVED!

 

anything