0

I'm writing a program in C# that basically serves one simple purpose. It's supposed to act like a server for clients to ping. This server program is meant only to determine whether a computer is still on or not by returning the ping requests. I don't need the program to send any information back to the client other than responding to the ping requests. The simple ping response is enough information to acknowledge the computer running the application is still on.

I'm currently approaching this by using a TCP server/client. However, it appears that I'm unable to connect to the TCP server. Is this because the server needs to have port 80 open in order to be pinged? My TCP server code is based around this thread I found:

Send/Receive Bytes using TCP Sockets over internet (possibly using static IP)

Is there something inherently wrong with that method? Or is there a much easier way to create this simple server that only needs to accept and respond to ping requests?

Community
  • 1
  • 1
Generalkidd
  • 579
  • 1
  • 8
  • 22
  • 2
    You don't need a server so that a computer responds to ping requests. – Ahmed KRAIEM Oct 11 '13 at 15:21
  • I thought a computer needs to be actively listening for ping requests in order to respond? Cause if I just simply ping my computer's ip address, I get no response and 100% packet data loss. Is that because of firewall settings or ports? – Generalkidd Oct 11 '13 at 15:25
  • I think it can be firewall setting that disallow pinging.. But can't you even ping your own computer's ip address (e.g. 127.0.0.1)? – rcs Oct 11 '13 at 15:29
  • You're right, I can ping my own computer if I do it from the same system. But I can't seem to ping it over the internet or over a local network from another computer. – Generalkidd Oct 11 '13 at 15:36
  • @Generalkidd - Definitely a firewall. See [here](http://answers.microsoft.com/en-us/windows/forum/windows_7-networking/how-to-enable-ping-response-in-windows-7/5aff5f8d-f138-4c9a-8646-5b3a99f1cae6) for how to enable pings to get through. – Bobson Oct 11 '13 at 15:47

2 Answers2

3

What do you do on the client side? Call ping on the console? This will not work, since ping is not based on TCP. If you are working around this code your client would have to connect on TCP port 9999 to get any response --> So you also need to develop a special ping application on client side. The client also wouldn't be able to send anything (like a ping), because the server only accepts the client, sends sth. and then closes the connection.

The default ping mechanism (based on ICMP) should already be available through your operating system and be sufficient for your use case. Is it not there? This might be related to some Ethernet settings or a firewall.

Matthias247
  • 9,836
  • 1
  • 20
  • 29
  • Ok so if I ignore TCP and just use the default ping mechanism, what port do ping requests come in from? I can't ping my computer from other computers whether over the internet or local networks. – Generalkidd Oct 11 '13 at 15:39
  • ping uses ICMP packets and does not use any port numbers.Here are some more details about it: http://en.wikipedia.org/wiki/Ping_%28networking_utility%29 If you can't ping it from another PC in the network then it's most likely a firewall issue directly on the PC. That ping is not running from the internet is normal, because your router won't know where to send the ping packet and will simply drop it. – Matthias247 Oct 11 '13 at 15:46
  • So if I wanted to ping from the internet I would need to set up a web server or something like that in IIS so the router knows where to send the ping request? – Generalkidd Oct 11 '13 at 17:30
0

You could open a socket on the server on a specific port, then attempt to connect to it using your client, exactly like in the link you've posted.