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 - 3N1GM4

Pages: [1]
1
Network / Re: Udp sockets don't seem to be working
« on: September 12, 2013, 07:52:38 am »
Forgot to add an exception to my firewall.. so yes, it works now-somewhat.
Sockets send and receive perfectly when the two computers share a public ip, but when their public ip's are different nothing happens.

2
Network / Udp sockets don't seem to be working
« on: September 11, 2013, 06:41:40 pm »
So I tried creating an application using udp sockets. I messed around with it a bit and didn't seem to be able to get it to work.. so I decided to just copy/paste the example code from the class reference.

void main()
{
char ctype;
cin>>ctype;
if (ctype=='c')
{
        // ----- The client -----
        // Create a socket and bind it to the port 55001
        sf::UdpSocket socket;
        socket.bind(55001);
        // Send a message to 192.168.1.50 on port 55002
        std::string message = "Hi, I am " + sf::IpAddress::getLocalAddress().toString();
        socket.send(message.c_str(), message.size() + 1, "192.168.1.50", 55002);
        // Receive an answer (most likely from 192.168.1.50, but could be anyone else)
        char buffer[1024];
        std::size_t received = 0;
        sf::IpAddress sender;
        unsigned short port;
        socket.receive(buffer, sizeof(buffer), received, sender, port);
        std::cout << sender.toString() << " said: " << buffer << std::endl;
}
else
{
        // ----- The server -----
        // Create a socket and bind it to the port 55002
        sf::UdpSocket socket;
        socket.bind(55002);
        // Receive a message from anyone
        char buffer[1024];
        std::size_t received = 0;
        sf::IpAddress sender;
        unsigned short port;
        socket.receive(buffer, sizeof(buffer), received, sender, port);
        std::cout << sender.toString() << " said: " << buffer << std::endl;
        // Send an answer
        std::string message = "Welcome " + sender.toString();
        socket.send(message.c_str(), message.size() + 1, sender, port);
}
}

Compiles without errors but when I run the application, nothing happens.
I should probably say that the two computers I'm using are connected to the internet using a wireless router and have the same Public IP.

A solution to this beginners' problem would be appreciated a lot- maybe I'm just missing something really simple..?

Thanks in advance

Pages: [1]
anything