Skip to main content
GameDev.net gamedev.net
🔒 Locked

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

Started by FFMG Jul 6, 2010 at 3:14 AM 10 replies 9.7k views
Original Post
FFMG
FFMG
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
Evil Steve
Evil Steve
What's wrong with just connecting to the target machine? If it succeeds, then the settings are correct, otherwise they're not.
FFMG
FFMG
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
simonlourson
simonlourson
I don't even know if it's possible in your language, but ping would be my choice
Antheus
Antheus
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.
hplus0603
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.

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."

enum Bool { True, False, FileNotFound };
FFMG
FFMG
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

MoOshiCow
MoOshiCow
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 ) 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.

rip-off
rip-off
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.
hplus0603
hplus0603
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.
enum Bool { True, False, FileNotFound };
FFMG
FFMG
Quote:
Original post by hplus0603
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.


Hum, sorry indeed, I don't think I understood you originally.

Are you saying that I should try to connect my client app to my server app?

This is not what I want to do, because there could be more problems than just a wrong IP address. Maybe the server app was not installed properly, maybe the client app was not.

If you are saying that the Client app can open a TCP socket without the need of a server app then I am not sure if that can be done, (but I could be wrong).

FFMG
hplus0603
hplus0603
If you read what we have been saying, then there is no way for the client app to know the difference between "wrong IP address" and "server has not been installed."

However, you sort-of don't care. All you care about is whether the IP/port works or not. If it doesn't work, then tell the user "this value doesn't work." if it works, tell the user "this value appears to work."

If you want to test whether the client app can connect to anything at all, then run your own server as well, on a known name/port (not IP, because those change over time!), and try to connect to that as well. If that doesn't work, then the client may be offline, badly installed, or your own server is temporarily offline (again, no way for the client to tell the difference).

Think about it this way: If the wrong IP address is entered, then there's no way for the client (or anyone, really) to know whether the computer at that address is one that the owner has intended to install the server on, or not. Only if there is a working server can you know that it's a machine where the server is intended to run.

The way most people get around this problem is to have a matchmaker/lobby/registry where active servers register themselves, and the user gets to choose a server from a list it gets from this roster server, rather than type something in. This means that you have to operate a roster server 24/7, which is one of the costs of doing networked game business on the internet.
enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.