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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Xavier59

Pages: [1]
1
Network / Re: Starting with Packet and Udp Socket
« on: September 03, 2015, 05:05:03 pm »
This was the error ! It's now working...
I'm so sorry to annoyed you with that as I'm starting in POO !
Thanks.
NB: Is there a way to put the topic on "resolve" or something like that ? :)

2
Network / Re: Starting with Packet and Udp Socket
« on: September 03, 2015, 07:18:27 am »
I am using any specific port on my computer for sending and receiving as it is client side.
But I use, in my constructor :

mySocket socket(12800);

Then, I am trying to send a packet via the port 12800 of my server :

m_socket.send(sendPacket, m_address, m_port)

Thanks.

3
Network / Re: Starting with Packet and Udp Socket
« on: September 03, 2015, 12:21:57 am »
I disabled my firewall for test, as I did for my anti-virus. But this isn't working.
I also tryed
sf::IpAddress m_address("127.0.0.1");
without more success.
Thanks.

4
Network / Re: Starting with Packet and Udp Socket
« on: September 02, 2015, 11:49:14 pm »
Of course I did !
There is not a single packet exiting my computer. And so it's not for the receiver.

5
Network / Re: Starting with Packet and Udp Socket
« on: September 02, 2015, 11:27:05 pm »
I just receive it simply (on the server) by doing that :

void createSocket(){
    unsigned short bindPort = 12800;
    unsigned short clientPort;
    int ret = 0;
    sf::UdpSocket socket;
    sf::IpAddress clientAddr;
    sf::Packet packet;
    Map mainMap;

    if (socket.bind(bindPort) != sf::Socket::Done){
        if (sf::Socket::Error) std::cout << "An unexpected error happened : Fatal Error !" << std::endl;
        if (sf::Socket::NotReady) std::cout << "The socket is not ready to send/receive data yet !" << std::endl;
    }

    std::cout << "The socket has been build and is ready to listen on port : " << bindPort << std::endl;

    while(1){
        packet.clear();
        socket.receive(packet, clientAddr, clientPort);
        std::cout << "A packet as been receive !" << std::endl;
        std::string header = readFromPacket(packet);
        ret = callFunction(packet, header, clientAddr, clientPort, mainMap, socket);
    }
}

But again, as it is UDP socket, I don't see how the receive method I use on my server could influence the fact that I can't send an UDP packet on the client side.

port 12 800 is open on the server. I didn't open port on the client as I didn't do it with python when i worked with socket (it was working :/ )

Btw, I want to communicate over computer who are not on the same network. But if it was the case, why an address like 82.236 is bad ? It will just take a little more time, isn't it ?


Thanks,
Xavier

6
Network / Re: Starting with Packet and Udp Socket
« on: September 02, 2015, 06:40:44 pm »
Where do you do receiving? You only show sending code.
Also if you use this, sf::Socket::AnyPort, on both server and client, there's no guarantee you will pick the correct port when trying to connect. Use a known socket something like 51234.

On the server side, it is fix to the port 12800.
I'm only showing sending code because as I can't send anything actually, I don't see the point to show receving code. Btw, my question stay, could the failure during sending packet be causes by a not working server ? As it is Udp packet, it couldn't be the case, but just to be sure.

7
Network / Re: Starting with Packet and Udp Socket
« on: September 02, 2015, 12:11:31 am »
I didn't find the solution.
As the server i'm working on is not fully working too, I would like to know if the failed to send the packet could be due to the unability from the server to receive the packet correctly ?
This appears strange to me but as far as I know, Udp is not secure, and then, do not need to know if the packet was receive (and then if the server really exists)
Thanks.

8
Network / [SOLVED] Starting with Packet and Udp Socket
« on: August 30, 2015, 09:29:38 pm »
Hello,

I am starting with SFML and networking. I' am trying to send a simple packet to a server but this does not work.
I know I am still a newbie, so if there is some huge and stupid errors, please take the time to explain me or to redirect me.

Here is my socket object (Udp):

#include <iostream>
#include "SFML/Network.hpp"
#include "decode.hpp"
#include "receive.hpp"

mySocket::mySocket(unsigned short port){
        unsigned short m_port = port;
        std::string m_error = "not error";
        sf::UdpSocket m_socket;
        sf::Packet m_packet;
        sf::IpAddress m_address("82.236.48.119");
}

int mySocket::buildSocket(bool blocking){               // return 0 if everything ok. else, -1
        m_socket.setBlocking(blocking);
        if(m_socket.bind(sf::Socket::AnyPort) != sf::Socket::Done){
                m_error = "Error in function buildSocket : Unable to find a port \n";
                return 0;
        }
        return 1;
}

sf::Packet mySocket::returnPacket(){            // return the packet
        return m_packet;
}

std::string mySocket::error(){
        return m_error;
}

int mySocket::sendPacket(sf::Packet& sendPacket){               // return 0 if there was an error. else, 1

        if(m_socket.send(sendPacket, m_address, m_port) != sf::Socket::Done){
                m_error = "Error in function sendPacket : Unable to send th packet";
                return 0;
        }
        m_error = "It's working !";
        return 1;
}

 

Here is my function :

void sendMessages(){
    mySocket socket(12800);
    sf::Packet packet;
    socket.buildSocket(false);

    std::string myString = "connection";
    while(1){
        Sleep(2000);
        packet << myString;
        std::string erreur = socket.error();
        std::cout << erreur << std::endl;
        socket.sendPacket(packet);
    }
}

Expected output :

Quote
It's working !

Actual output :

Quote
Error in function sendPacket : Unable to send th packet

Thanks,
Xavier

Pages: [1]
anything