🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Issues with RakNet and public IP

Started by
5 comments, last by antoniorv6 5 years, 5 months ago

Hi there.

I'm currently developing the online multiplayer for my college project. We have to develop it using RakNet library.

Now I am have successfully developed a server and client that can communicate from machines connected into the same network. The next step in the development that I want to make is to accomplish remote connections between clients and the server. I have read the docummentation of RakNet. As I have understood, there is no need to make IP forwarding, because NATPunchthrough plugin resolves the problem. I have followed the guidelines in the official webpage to make the basic connection. However, it doesn't work. I mean, the connection packet that de client sends to the public IP isn't recevied by the server, so I can't make any steps further (because i have to run the OpenNAT function after receiving the connection acceptance packet).

I tried to bind the public IP to the server, as I have seen in the forums with strcpy(socket.host, public_ip), but it just triggers an error and sets it to it's default.

I want to ask you if I am missing something or misunderstanding any concept.

Here's my code for the server, the part that corresponds on binding:


m_natPunch_ptr = RakNet::NatPunchthroughServer::GetInstance();
    m_peerInterface_ptr = RakNet::RakPeerInterface::GetInstance();
	m_peerInterface_ptr->AttachPlugin(m_natPunch_ptr);
	m_socketDescriptor_sock = RakNet::SocketDescriptor(m_SERVERPORT_i, 0);
    m_peerInterface_ptr->Startup(m_MAXCONNECTIONS_i,&m_socketDescriptor_sock,1);
    m_peerInterface_ptr->SetMaximumIncomingConnections(m_MAXCONNECTIONS_i);

    std::cout<<"[SUCCESS] - Server initialized correctly"<<std::endl;
    std::cout<<"The server GUID is ->"<<m_peerInterface_ptr->GetMyGUID().ToString()<<std::endl;
    std::cout<<"The server IP is   ->"<<m_peerInterface_ptr->GetSystemAddressFromGuid(m_peerInterface_ptr->GetMyGUID()).ToString()<<std::endl;

And here's the client corresponding one:


m_punchClient_ptr = RakNet::NatPunchthroughClient::GetInstance();
    m_peerInterface_ptr = RakNet::RakPeerInterface::GetInstance();
	m_peerInterface_ptr->AttachPlugin(m_punchClient_ptr);
	m_peerInterface_ptr->Startup(1,&m_socketDescriptor_sock,1);
	ConnectToServer();
    std::cout<<"I'm going to try to connect to the server"<<std::endl;
    m_peerInterface_ptr->Connect("My public IP",8000,0,0); //I retrieve my public IP with whatspmyip.com
    std::cout<<"Connecting..."<<std::endl;

Thank you very much in advance.

Advertisement

Did you open your port in your router settings?

ETA: I've never used RakNet just a suggestion.

NATPunchthrough plugin resolves the problem

It resolves the problem, if the server that does the punch-through is publicly available, and is responding on the appropriate port, and is not filtered by any firewall.

Where do you run the server? On some public cloud, like amazon, google, linode, azure, or somesuch? It needs to have a publicly reachable IP address. What is the address of the server? What is the address you tell the client to send to? If you use Wireshark on the client, or tcpdump on the server, what packets, ports, and addresses do you see?

enum Bool { True, False, FileNotFound };
17 minutes ago, hplus0603 said:

 

 

It resolves the problem, if the server that does the punch-through is publicly available, and is responding on the appropriate port, and is not filtered by any firewall.

Where do you run the server? On some public cloud, like amazon, google, linode, azure, or somesuch? It needs to have a publicly reachable IP address. What is the address of the server? What is the address you tell the client to send to? If you use Wireshark on the client, or tcpdump on the server, what packets, ports, and addresses do you see?

It finally was that the router didn't have the port opened. Changed it and worked fine. The server runs in a Manjaro device at home.

Anyway, there is something that confuses me. When I checked the port, the service told me that it was CLOSED. However, the client connected perfectly (I've put my public IP in the connect() function and tried in two sepparated devices). The server is also listening and using the same port.

Is it there anything that I'm skipping or doing wrong?

23 minutes ago, hplus0603 said:

On some public cloud, like amazon, google, linode, azure, or somesuch?

Nope, I'm now on developing proccess. But I have intentions to upload it to one cloud service (I don't want it running in my home router). Any recommendation about coosing one of these or considerations that I must have?

Thank you very much!

2 hours ago, antoniorv6 said:

...there is something that confuses me. When I checked the port, the service told me that it was CLOSED. However, the client connected perfectly (I've put my public IP in the connect() function and tried in two sepparated devices). The server is also listening and using the same port.

From my experience, when I was testing using a port checker, it would say CLOSED unless I had my server running and actively listening for new connections.

 

When my server was not running, it would show CLOSED.

 

When my server was running, it would show OPEN.

 

I hope this helps.

4 minutes ago, pindrought said:

From my experience, when I was testing using a port checker, it would say CLOSED unless I had my server running and actively listening for new connections.

 

When my server was not running, it would show CLOSED.

 

When my server was running, it would show OPEN.

 

I hope this helps.

Yeah, it was the result I was expecting. But either is the server active listening or not for new connections, it is shown the CLOSED status. That was what made me freak out. 

This topic is closed to new replies.

Advertisement