Jump to content
  • Advertisement
Sign in to follow this  
FFMG

Simple test to network connectivity, (C++).

This topic is 2903 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

My game allows the user to connect over the network but more often than not they make very basic mistakes, (like not entering the correct IP address of the networked machine).

So what I would like is a very simple 'test' function to check if the machine name and/or IP address given by the user actually exists and I can connect to it, (no firewall or something).

Would anybody have some code for me for such a function?

Many thanks in advance.

FFMG

Share this post


Link to post
Share on other sites
Advertisement
What's wrong with just connecting to the target machine? If it succeeds, then the settings are correct, otherwise they're not.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
What's wrong with just connecting to the target machine? If it succeeds, then the settings are correct, otherwise they're not.


There is nothing wrong with that, but then there could be more possible problems.
Was the listening app installed properly on the other machine?
Is the port number valid?
firewall settings, permissions

In my experience the users enter the wrong IP address first, and I just want to quick and simple way to check if a certain machine/IP address does indeed exist.

FFMG

Share this post


Link to post
Share on other sites
Quote:
Original post by FFMG

So what I would like is a very simple 'test' function to check if the machine name and/or IP address given by the user actually exists and I can connect to it, (no firewall or something).


Internet is designed in a way that makes this impossible.

The closest one can do is open a TCP socket to that IP+port, trying to connect to a your server and negotiate a handshake. If connection is refused, or it times out, or if received response is incorrect, it is possible to assume that destination is unreachable due to any number of reasons, including the destination not running the specific server.

For this reason, everyone is moving to fully or partially hosted solutions, where all matchmaking is done by authoritative and centralized matchmaker, which may even act as proxy or authoritative server (to avoid firewall issues).

Quote:
There is nothing wrong with that, but then there could be more possible problems.
Was the listening app installed properly on the other machine?
Is the port number valid?
firewall settings, permissions
Networking world has collectively given up on trying to answer these questions.

The underlying reason is simple - a service either works, or user will be clueless or powerless over how to fix it. Everything in between simply doesn't add any benefit - there is no "works kinda ok".

There exist network diagnostic tools which use decades-worth of heuristics trying to determine exact causes, but they don't really do much for end user to fix them.


Run a matchmaker, show a drop down list of available hosts.

Share this post


Link to post
Share on other sites
If you want to support peer-to-peer connections without matchmaking, then I think trying to simplify the user experience is a good goal, but you really can't make it as seamless as you could if you had a central matchmaker server.

From a UI perspective, I think it makes sense to have a "test connection" button right there, where you enter the IP address and port.

User can enter IP and port, and press "test connection." If it fails, then the message should say something like "either the address is wrong, or the server is not accessible."

Share this post


Link to post
Share on other sites
Quote:
Original post by hplus0603
If you want to support peer-to-peer connections without matchmaking, then I think trying to simplify the user experience is a good goal, but you really can't make it as seamless as you could if you had a central matchmaker server.


I don't really want to make it 100% seamless, I just want to remove the common mistakes.
If I can break it down in simple steps then it will make it easier to diagnose.
1- Can it ping the other machine.
2- Can it handshake the app on the other machine.

If steps 1 fails then there is no point in going any further.

Quote:

From a UI perspective, I think it makes sense to have a "test connection" button right there, where you enter the IP address and port.


Exactly, putting my app aside, I want to first test if the other machine is even accessible in the first place.

Quote:

User can enter IP and port, and press "test connection." If it fails, then the message should say something like "either the address is wrong, or the server is not accessible."


This is the function I am looking for, a simple 'ping' function.

Would you know of one?

Thanks

FFMG

Share this post


Link to post
Share on other sites
I'm not entirely sure what's wrong with trying to first connect to said IP address, and if it fails then there's something wrong with the server address, setting, etc.
But anyways, here's a pinging solution on windows (i.e. using MSDN) :

http://msdn.microsoft.com/en-us/library/ms682499%28v=VS.85%29.aspx

Basically, create a Ping command process (like, "ping -n 1 <ip>) and then capture the output with the CreatePipe function.

Then, using the output, you can figure out your ping with the server, or if your ping timed out or failed, etc.

Share this post


Link to post
Share on other sites
Ping is not sure-fire. ICMP packets are sometimes blocked between networks, because historically there have been DOS attacks made with them. Just because you cannot ping a host, doesn't mean you cannot connect to it.

However, you could try pinging a host that fails a connection, and use that to infer the problem. It will still be a guess though.

As Antheus mentioned, from the users perspective "host not found" and "host not responding to connection, but it exists" are effectively the same error. The client must double check the IP address or host name, or try connection to a different server/game.

That said, game administrators might appreciate more fine grained error messages if they were trying to connect to the games administrative console, because they can undertake more actions to fix the problem.

Share this post


Link to post
Share on other sites
Quote:
This is the function I am looking for, a simple 'ping' function.


I don't think you understood my proposed solution:
Simply try to connect to the server. Open a TCP socket to the given IP and port. If it works, great! If not, tell the user.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!