Generalkidd
Generalkidd

Reputation: 579

C# simple server for pinging only

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?

Upvotes: 0

Views: 2637

Answers (2)

Andrei Tanasescu
Andrei Tanasescu

Reputation: 26

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.

Upvotes: 0

Matthias247
Matthias247

Reputation: 10426

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.

Upvotes: 3

Related Questions