Jump to content
  • Advertisement
antoniorv6

Issues with RakNet and public IP

Recommended Posts

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.

Edited by antoniorv6

Share this post


Link to post
Share on other sites
Advertisement

Did you open your port in your router settings?

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

Edited by pindrought

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!