Jump to content

Communication between autoit and php


Recommended Posts

Hi, i'm trying to make communication between script in autoit and php script. I tried communication via file but i think it's too slow. Now i trying to make it on TCP but something is wrong and scripts doesn't work. this is the code of scripts:

#include <ScreenCapture.au3>

TCPStartup()
OnAutoItExitRegister("OnAutoItExit")

Global $Client

_ScreenCapture_SetJPGQuality(35)
$Listen = TCPListen("127.0.0.1", 3030, 20)
While 1
    $Client = TCPAccept($Listen)
    If $Client <> -1 Then
        _ScreenCapture_Capture("D:/xampp/htdocs/desktop.jpg")
        TCPSend($Client, "1")
    EndIf
    Sleep(5)
WEnd

Func OnAutoItExit()
    TCPShutdown()
EndFunc
<?php
    $fp = fsockopen("127.0.0.1", 3030);
    while(fgets($fp, 2) != "1"))
    {
            usleep(5000);
    }
?>

The PHP server is local. I trying to achieve if i execute php script that connecting to tcp autoit server and wait for response string "1" then just exit.

Edited by MrKris1224
Link to comment
Share on other sites

It might help to debug if error checking was in place...

#include 'ScreenCapture.au3'
;
Opt('MustDeclareVars', 1)
;
TCPStartup()
Opt('TCPTimeout', 10); <- needed for Autoit v3.3.10 to v3.3.15
OnAutoItExitRegister("OnAutoItExit")
;
Local $Client, $Listen, $nError, $sFile = 'D:\xampp\htdocs\desktop.jpg'
_ScreenCapture_SetJPGQuality(35)
;
$Listen = TCPListen("127.0.0.1", 3030, 20)
$nError = @error
If $nError Then
    MsgBox(8208, 'Error', 'TCPListen: ' & $nError)
    Exit
EndIf
;
While 1
    $Client = TCPAccept($Listen)
    If $Client > 0 Then
        If FileExists($sFile) Then
            FileDelete($sFile)
        EndIf
        ;
        _ScreenCapture_Capture($sFile)
        TCPSend($Client, "1")
        $nError = @error
        If $nError Then
            MsgBox(8208, 'Error', 'TCPSend: ' & $nError)
        EndIf
        ;
        Sleep(1000)
        TCPCloseSocket($Client)
    EndIf
    Sleep(10)
WEnd
;
Func OnAutoItExit()
    TCPShutdown()
EndFunc

 

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

I don't know about php, so I have no way to test it from that side.

The script I posted above does work with another AutoIt script that I used to test with.

So, perhaps the issue is on the php side.

(OT: I wonder what happened to the post number counts in the forum. I sure do miss them!)

 

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

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...