Пример #1
0
def checkTcpConnectivity(ipAddress, portNumber, timeout):
    """
    Checks the  TCP connection to the given ipAddress on the given port.
    @param ipAddress: IP address of the remote computer to check
    @type ipAddress: String
    @param portNumber: The port number to check
    @type portNumber: int
    @param timeout: connection timeout in millisecondes
    @type timeout: int
    @return 1 if the TCP connection succeeded, else
    """
    socket = None
    try:
        socket = Socket()
        socket.connect(InetSocketAddress(ipAddress, portNumber), timeout)
        logger.debug('Connected to port:', portNumber, ' on host by ip:',
                     ipAddress)
        #check that the object is not null
        if (socket != None):
            try:
                #try to close the socket
                socket.close()
            except:
                #we failed to close the socket - let's log it...
                logger.debug('Failed to close socket')
        return 1
    except IOException, e:
        logger.debug('Failed to connect to port:', portNumber,
                     ' on host by ip:', ipAddress,
                     ' IOException(', e.getMessage(), ')')
        return 0
Пример #2
0
def checkTcpConnectivity(ipAddress, portNumber, timeout):
    """
    Checks the  TCP connection to the given ipAddress on the given port.
    @param ipAddress: IP address of the remote computer to check
    @type ipAddress: String
    @param portNumber: The port number to check
    @type portNumber: int
    @param timeout: connection timeout in millisecondes
    @type timeout: int
    @return 1 if the TCP connection succeeded, else
    """
    socket = None
    try:
        socket = Socket()
        socket.connect(InetSocketAddress(ipAddress, portNumber), timeout)
        logger.debug('Connected to port:', portNumber, ' on host by ip:',
                     ipAddress)
        #check that the object is not null
        if (socket != None):
            try:
                #try to close the socket
                socket.close()
            except:
                #we failed to close the socket - let's log it...
                logger.debug('Failed to close socket')
        return 1
    except IOException, e:
        logger.debug('Failed to connect to port:', portNumber,
                     ' on host by ip:', ipAddress, ' IOException(',
                     e.getMessage(), ')')
        return 0
Пример #3
0
 def issueRequest(cls, targetHost, targetPort, forPlayerName, requestContent, timeoutClock):
     """ generated source for method issueRequest """
     socket = Socket()
     theHost = InetAddress.getByName(targetHost)
     socket.connect(InetSocketAddress(theHost.getHostAddress(), targetPort), 5000)
     HttpWriter.writeAsClient(socket, theHost.getHostName(), requestContent, forPlayerName)
     response = HttpReader.readAsClient(socket) if (timeoutClock < 0) else HttpReader.readAsClient(socket, timeoutClock)
     socket.close()
     return response