Jump to content

SOCKET BETWEEN PYTHON AND AUTOIT


 Share

Recommended Posts

Hello,

I've a simple socket script in python on a linux machine :
 

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', 6542))
s.listen(5)
conn, addr = s.accept()
while True:
    data = conn.recv(1024)
    if not data:
        break
    print data
    conn.sendall("TEST EMISSION")
conn.close()


I would like send data with autoit... 
 

#include <MsgBoxConstants.au3>

Example()

Func Example()
    TCPStartup() ;
    OnAutoItExitRegister("OnAutoItExit")
    Local $sIPAddress = "10.40.16.212" 
    Local $iPort = 6542 
    Opt("TCPTimeout", 3000

    Local $iSocket = TCPConnect($sIPAddress, $iPort)
    If @error Then
        Local $iError = @error
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Connexion impossible, code d'erreur: " & $iError)
        Return False
    Else
        MsgBox($MB_SYSTEMMODAL, "", "Connection réussie")
    EndIf
    TCPCloseSocket($iSocket)
EndFunc   ;==>Example

Func OnAutoItExit()
    TCPShutdown() 
EndFunc  


It doesn't work. I try AUTOIT with AUTOIT it's ok. Python with python too... 
Some ideas?

Thanks in advance

Link to comment
Share on other sites

Hi.. and welcome to the forums. Unfortunately, "doesn't work" isn't enough details for us to help you. Please provide a more detailed description of what is occurring. I assume that 10.40.16.212 is the IP address of the linux machine. Is it on the same subnet as your Windows machine? Any chance there's a firewall between them?

I'm not sure if it's simply a copy / paste issue, but the line containing Opt("TCPTimeout" is missing a closing parentheses. Also, here's the proper way to post code in the future.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...