Connection only works with manually set values

0

I have a Socket class that is working normally this way:

class Socket():
    __ffChatSocket = ""
    __meuTelefone = ""
    __WhatsappAPI = ""
    __dest = ()

    def __init__(self, telefone, WhatsappAPI):
        ip = str(self.getFileConfigFF('infoserver','ip'))
        port = int(self.getFileConfigFF('infoserver','port'))
        self.__dest = (ip, port)
        self.__meuTelefone = telefone
        self.socketConnect()
        self.__WhatsappAPI = WhatsappAPI

    def socketConnect(self):
        try:
            self.__ffChatSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.__ffChatSocket.connect(("172.20.50.243", 4321)))
            self.__ffChatSocket.send(self.criarEvento("onCompleteConnection", [self.getNumeroFuturoFone()]))
            thread.start_new_thread(self.socketReceiveData, ())
        except Exception as erro:
            self.logErro("Conexao falhou ")
            self.logErro("O erro foi: ")
            self.logErro(erro)
            self.reconectarSocket()

    def getFileConfigFF(self, tag, subTag):
        Config = configparser.ConfigParser()
        pastaLocal = os.path.dirname(os.path.abspath(__file__))
        Config.read(pastaLocal + '\config.ini')
        caminho = re.findall('"([^"]*)"', Config[tag][subTag])
        return caminho[0]

But I want to get the ip and port for an .ini file, I've already performed several tests using the getFileConfigFF method and it picks up the values normally.

I tried to assign the values for the connect method in several ways like:

dest = (ip, port)
self.__ffChatSocket.connect(dest)

or

self.__ffChatSocket.connect((ip, port))

I tried to get the values using cast (str and int) and also without the cast, but it always has the same error when trying to connect:

[Errno 10061] Nenhuma conexÒo p¶de ser feita porque a mßquina de destino as recusou ativamente

This is the last code I tested:

class Socket():
    __ffChatSocket = ""
    __meuTelefone = ""
    __WhatsappAPI = ""
    __dest = ()

    def __init__(self, telefone, WhatsappAPI):
        ip = str(self.getFileConfigFF('infoserver','ip'))
        port = int(self.getFileConfigFF('infoserver','port'))
        self.__dest = (ip, port)
        self.__meuTelefone = telefone
        self.socketConnect()
        self.__WhatsappAPI = WhatsappAPI

    def socketConnect(self):
        try:
            self.__ffChatSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            pprint(self.__dest)
            self.__ffChatSocket.connect(self.__dest)
            self.__ffChatSocket.send(self.criarEvento("onCompleteConnection", [self.getNumeroFuturoFone()]))
            thread.start_new_thread(self.socketReceiveData, ())
        except Exception as erro:
            self.logErro("Conexao falhou ")
            self.logErro("O erro foi: ")
            self.logErro(erro)
            self.reconectarSocket()

    def getFileConfigFF(self, tag, subTag):
        Config = configparser.ConfigParser()
        pastaLocal = os.path.dirname(os.path.abspath(__file__))
        Config.read(pastaLocal + '\config.ini')
        caminho = re.findall('"([^"]*)"', Config[tag][subTag])
        return caminho[0]

I put pprint (self .__ dest) before the connection to show the value that was set to self .__ dest and what is shown on the screen is:

('172.20.50.247', 4433)

In other words, the ip and port are right, but I do not understand why it is not connected and why it connects normally when the values are set manually.

    
asked by anonymous 14.09.2017 / 17:06

1 answer

0

The problem was with encode, how do I get the port and ip values.

    
28.09.2017 / 21:05