How to check the connection to the server

I want to test the connection to the server to see if it is available or not in order to inform the user.

since send pkg or msg to server (this is not a SQL server, and the server contains some servlets) ...

thnx in adcvance ..

-1


source to share


2 answers


With all the power for firewalls to block ICMP packets or specific ports, the only way to ensure that a service is running is to do something that uses that service.

For example, if it is a JDBC server, you can execute a non-destructive SQL query, such select * from sysibm.sysdummy1

as against DB2. If it is an HTTP server, you can create a GET package for index.htm.

Once you have control over the service, simply create a dedicated sub-service to handle these requests (for example, you send via a CHECK packet and return an OKAY response).



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

Take this from someone who had to fight the network gods in a corporate environment where machines are locked in as tightly as the proverbial fish ...

+3


source


If you can open a port but don't want to ping (I don't know why, but hey), you can 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 than a simple python python server listening on 55555 and returning pending

0


source







All Articles