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

Author Topic: Problem with IP  (Read 5651 times)

0 Members and 1 Guest are viewing this topic.

Nexy

  • Newbie
  • *
  • Posts: 9
    • View Profile
Problem with IP
« on: September 20, 2010, 09:27:25 am »
Hello,
I've problem with server and client connection.

Server:

Quote
#include <SFML/Network.hpp>
#include <iostream>


int main()
{
    const unsigned short Port = 2435;

    sf::SocketUDP Server;
    if (!Server.Bind(Port))
    {
        std::cout << " error" << std::endl;
    }

    sf::Packet Packet;
    sf::IPAddress ClientAddress;
    unsigned short ClientPort;
    Server.Receive(Packet, ClientAddress, ClientPort);

    int a;
    Packet >> a;
    std::cout << "packet : " << a << " from "<< ClientAddress <<" port: "<< ClientPort << std::endl;

    a=12345;
    Packet.Clear();
    Packet << a;
    Server.Send(Packet, ClientAddress, ClientPort);

    std::cin.ignore(10000, '\n');
    Server.Close();
    return EXIT_SUCCESS;
}


Client:

Quote
#include <SFML/Network.hpp>
#include <iostream>


int main()
{
    const unsigned short Port = 2400;

    sf::SocketUDP Client;
    if (!Client.Bind(Port))
    {
        std::cout << " error" << std::endl;
    }

    sf::Packet Packet;
    sf::IPAddress ServerAddress;
    unsigned short ServerPort=2435;

    int a;
    a=54321;
    Packet << a;
    Client.Send(Packet, ServerAddress, ServerPort);

    Packet.Clear();
    Client.Receive(Packet, ServerAddress, ServerPort);

    Packet >> a;
    std::cout << "packet : " << a << " from "<< ServerAddress <<" port: "<< ServerPort << std::endl;

    std::cin.ignore(10000, '\n');
    Client.Close();
    return EXIT_SUCCESS;
}


When I use "IPAddress ClientAddress;" it works. But when I use:

Quote
IPAddress::GetPublicAddress();
or
Quote
IPAddress Address("83.145.154.170");
it doesn't work!

This IP is from http://whatismyip.org

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Problem with IP
« Reply #1 on: September 20, 2010, 09:30:36 am »
What is your network configuration ?
Have you 2 computers ?
Are you connected to the Internet ? How ?
Mindiell
----

Nexy

  • Newbie
  • *
  • Posts: 9
    • View Profile
Problem with IP
« Reply #2 on: September 20, 2010, 03:27:01 pm »
Thanks for reply. I'm using one computer with Motorola modem:



When I use
Quote
IPAddress ClientAddress;
program use "255.255.255.255", not "83.145.154.170". Why? Someone can help me?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problem with IP
« Reply #3 on: September 20, 2010, 04:16:12 pm »
Quote
When I use
Quote
IPAddress ClientAddress;

program use "255.255.255.255", not "83.145.154.170". Why? Someone can help me?

It gives an invalid address because you don't put a valid address in it ;)
Code: [Select]
IPAddress ClientAddress = "83.145.154.170";
Laurent Gomila - SFML developer

Nexy

  • Newbie
  • *
  • Posts: 9
    • View Profile
Problem with IP
« Reply #4 on: September 20, 2010, 04:28:17 pm »
When I use
Code: [Select]
IPAddress ClientAddress/ServerAddress = "83.145.154.170"; it doesn't work! It works only with:
Code: [Select]
IPAddress ClientAddress/ServerAddress;

Why?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problem with IP
« Reply #5 on: September 20, 2010, 04:44:03 pm »
Using a default-constructed IPAddress gives an invalid address, but this address is also the UDP broadcast address. That's why you can reach everyone on your local network when using such an address, but not outside (broadcast messages are blocked by the router).

If you want to use a public IP address, make sure that the router doesn't block the corresponding port.
Laurent Gomila - SFML developer

Nexy

  • Newbie
  • *
  • Posts: 9
    • View Profile
Problem with IP
« Reply #6 on: September 20, 2010, 05:43:58 pm »
I used about 30 port and nothing. They are reserved or what? How I can check free ports in my router?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Problem with IP
« Reply #7 on: September 20, 2010, 06:01:27 pm »
You need to open your own port, ports that are already opened are obviously already used as well.
Laurent Gomila - SFML developer

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Problem with IP
« Reply #8 on: September 21, 2010, 08:59:15 am »
Have you a firewall ?
Can you modify the ports the modem let available ?
Mindiell
----

Nexy

  • Newbie
  • *
  • Posts: 9
    • View Profile
Problem with IP
« Reply #9 on: September 21, 2010, 04:05:45 pm »
Quote from: "Mindiell"
Have you a firewall ?
Can you modify the ports the modem let available ?


No, I don't have firewall and I don't know why it doesn't work.

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Problem with IP
« Reply #10 on: September 22, 2010, 08:46:34 am »
So, can you try the SFML network samples ? Is this working ?
Mindiell
----

Nexy

  • Newbie
  • *
  • Posts: 9
    • View Profile
Problem with IP
« Reply #11 on: September 22, 2010, 03:00:10 pm »
Quote from: "Mindiell"
So, can you try the SFML network samples ? Is this working ?


No :(
It's working only with "127.0.0.1", not "83.145.154.170".

Krosan

  • Newbie
  • *
  • Posts: 10
    • View Profile
Problem with IP
« Reply #12 on: September 22, 2010, 03:38:57 pm »
is the modem just a modem or is it a router?
your pc behind the modem has a private or public ip?

thanks..

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Problem with IP
« Reply #13 on: September 22, 2010, 04:21:20 pm »
Quote from: "Krosan"
your pc behind the modem has a private or public ip?
Under Windows : Execute : cmd
then ipconfig

Under Linux : ifconfig in a terminal ;)
Mindiell
----

 

anything