views:

632

answers:

2

Dear all;

i want to check my server connection to know if its available or not to inform the user..

so how to send a pkg or msg to the server (it's not SQL server; it's a server contains some serviecs) ...

thnx in adcvance ..

+3  A: 

With all the possibilities for firewalls blocking ICMP packets or specific ports, the only way to guarantee that a service is running is to do something that uses that service.

For instance, if it were a JDBC server, you could execute a non-destructive SQL query, such as select * from sysibm.sysdummy1 for DB2. If it's a HTTP server, you could create a GET packet for index.htm.

If you actually have control over the service, it's a simple matter to create a special sub-service to handle these requests (such as you send through a CHECK packet and get back an OKAY response).

That way, you avoid all the possible firewall issues and the test is a true end-to-end one. PINGs and traceroutes will be able to tell if you can get to the machine (firewalls permitting) but they won't tell you if your service is functioning.

Take this from someone who's had to battle the network gods in a corporate environment where machines are locked up as tight as the proverbial fishes ...

paxdiablo
A: 

If you can open a port but don't want to use ping (i dont know why but hey) you could use something like this:

import socket

host = ''
port = 55555

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host, port))
s.listen(1)

while 1:
    try:
        clientsock, clientaddr = s.accept()
        clientsock.sendall('alive')
        clientsock.close()
    except:
        pass

which is nothing more then a simple python socket server listening on 55555 and returning alive

Unkwntech