Jump to content

Sending autoit Commands between two .EXE's


Recommended Posts

Is there a way to send an AutoIt command between two compiled scripts?

I have a Server Side program and a Client side program that are communicating. I need to be able to make the server side program request a Name from the client side , in order to store that name into a value for an array to create the socket for that connection.

Any ideas, or is this possible?

Link to comment
Share on other sites

Is there a way to send an AutoIt command between two compiled scripts?

I have a Server Side program and a Client side program that are communicating. I need to be able to make the server side program request a Name from the client side , in order to store that name into a value for an array to create the socket for that connection.

Any ideas, or is this possible?

tcpsend...?

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Link to comment
Share on other sites

I tried this:

HotKeySet('!n', '_MsgBox')

;Body

Func _MsgBox()

$MsgBox = MsgBox( 0, "Working", "Sending a command works.")

TcpSend($iConnectedSocket, $MsgBox)

EndFunc

And well , the msgbox... MsgBox( 0, "Working", "Sending a command works.")..... pops up on the server and a msgbox containing " 0x01000000 " pops up on the client side.

Link to comment
Share on other sites

triple post?

I'm not great with tcp, but you maybe be recieving the command wrong.

TCPAccept args?

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

Sorry about triple post. My computer did something wierd when I went to post it.

I got it to work like this:

SERVER-SIDE

Func _MsgBox()
;~  $MsgBox = MsgBox( 0, "Working", "Sending a command works.")
    TcpSend($iConnectedSocket, "$MsgBox")
EndFunc

CLIENT-SIDE

If $MsgBox Then
;~          MsgBox( 0, "Works", "Works")
            FileExists( @ScriptDir& "\TCP Funcs.au3")
        EndIf
            If $FileExists = 1 Then
                TcpSend($Socket, "This is the return code for $FileExists: "&$FileExists)
        EndIf

Problem is... thats on a loop and it sends it to the server OVER AND OVER AND OVER. Maybe if I take it out of the loop... I'm trying that now....

That didn't work. It's no longer responding to the hotkey that makes the server ask the client if FileExists.

Any ideas?

Link to comment
Share on other sites

Sorry about triple post. My computer did something wierd when I went to post it.

I got it to work like this:

SERVER-SIDE

Func _MsgBox()
;~  $MsgBox = MsgBox( 0, "Working", "Sending a command works.")
    TcpSend($iConnectedSocket, "$MsgBox")
EndFunc

CLIENT-SIDE

If $MsgBox Then
;~          MsgBox( 0, "Works", "Works")
            FileExists( @ScriptDir& "\TCP Funcs.au3")
        EndIf
            If $FileExists = 1 Then
                TcpSend($Socket, "This is the return code for $FileExists: "&$FileExists)
        EndIf

Problem is... thats on a loop and it sends it to the server OVER AND OVER AND OVER. Maybe if I take it out of the loop... I'm trying that now....

That didn't work. It's no longer responding to the hotkey that makes the server ask the client if FileExists.

Any ideas?

all that tcpsend is doing is sending text so what you need to do is tcpsend whatever then on the client tcprecieve and then based on the text it gains set the variable ill right an example if you don't figure it out.

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Link to comment
Share on other sites

You have to use TCPRecieve() to get the message from the server, he is saying. And if you can't figure it out, he'll post an example.

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

I know what hes saying, I'm just mentioning asking if thats what I did in the examples I gave. Now realizing I didn't include the parts where I TCPRecv'd etc. So I'm going to include both scripts in their entirety.

SERVER-SIDE

#Include <Array.au3>
HotKeySet('!c', '_Test'); Set up an A hotkey to send the message
HotKeySet('!n', '_MsgBox')

Dim $iMainSocket = 0
Dim $iConnectedSocket = -1
Dim $sData = ""
;~ Dim $Sockets[0]
TCPStartup() 
$iMainSocket = TCPListen(@IPAddress1,7000)
    
While 1
    If $iConnectedSocket >= 0 Then 
;~        ArrayAdd( $Sockets, $UserValue)
        $sData = TCPRecv($iConnectedSocket,1024) 
        $UserValue = TCPRecv($iConnectedSocket, 1024)
        $Vara = TCPRecv($iConnectedSocket, 1024)
        $IP = TcpSend($iConnectedSocket, "$GetIp")
        If @error Then 
            $iConnectedSocket = -1
            ConsoleWrite("Client has disconnected" & @CRLF)
;~       ElseIf $sData Then 
;~           MsgBox(0, "Message Received", $sData)
        ElseIf $UserValue Then
                MsgBox( 0, "Value", "The users value in the array is: "&$UserValue)
        EndIf
        If $Vara Then
            $FFF = FileExists( @DesktopDir& "\Logs\IP.txt")
            If $FFF = 1 Then
                $FFFF = IniRead( @DesktopDir&"\Logs\Ip.ini", "IP_Addresses", ""&$GetIp, "NotFound")
                If $FFFF = NotFound Then
                    IniWrite(@DesktopDir&"\Logs\Ip.ini", "IP_Addresses", ""&$GetIp, ""&$GetIp)
                EndIf
            EndIf
        EndIf   
    Else 
        $iConnectedSocket = TCPAccept($iMainSocket) 
        If $iConnectedSocket >= 0 Then
            ConsoleWrite("Connection established" & @CRLF)
        EndIf
    EndIf
Wend

Func _Test()
;$Ip = _GetIp()
    $Input = InputBox( "Message", "What message do you want to send the client?")
    TCPSend($iConnectedSocket, $Input); Send the data
EndFunc
Func _MsgBox()
;~  $MsgBox = MsgBox( 0, "Working", "Sending a command works.")
    TcpSend($iConnectedSocket, "$MsgBox")
EndFunc

CLIENT SIDE

#include <INet.au3>

HotKeySet('!b', '_Test'); Set up an A hotkey to send the message
HotkeySet( '!a', '_Ip')
HotKeySet('{ESC}', '_Close'); Call a close function to close the script when someone presses escape
HotKeySet('!v', '_Value')
TCPStartup(); Initialize the TCP functions/library



$Socket = TCPConnect( "64.22.75.225", 7000); Connect to the server
If @error Then; If no connection is made, the server probably is not running, or another error occurs, give an error message to the user
    MsgBox(0x20,"Connection error", "Unable to connect.")
    Exit; Close the script
EndIf
$Ip = _GetIp()
$UserValue = $Ip
$FileExists = FileExists( @ScriptDir& "\TCP Funcs.au3")
TCPSend($Socket,$Ip& " has just connected."); Just send a test message to make sure we can send some data. ( Not necessary )

While 1
        $sData = TCPRecv($Socket,1024) 
            If $sData Then 
            MsgBox(0, "Message Received", $sData)
        EndIf
        $MsgBox = TCPRecv($Socket, 1024)
        If $MsgBox Then
;~          MsgBox( 0, "Works", "Works")
            FileExists( @ScriptDir& "\TCP Funcs.au3")
        EndIf
            If $FileExists = 1 Then
                TcpSend($Socket, "$Vara")
            EndIf
            $GetIp = TcpRecv($Socket, 1024)
        If $GetIp Then
            Send( '!a')
        EndIf
    WEnd
    

Func _Test()
;$Ip = _GetIp()
    $Input = InputBox( "Message", "What message do you want to send the server?")
    TCPSend($Socket, $Input); Send the data
EndFunc

Func _Ip()
    TcPSend($Socket, "The users IP is: "&$Ip)
EndFunc

Func _Value()
    TcpSend($Socket, $UserValue)
EndFunc

Func _Close()
    TCPCloseSocket($Socket); Close the socket to the server
    TCPShutdown(); Deinitialize the TCP functions/library
    Exit; Close the script
EndFunc

It's not exactly the neatest code. I was doing alot of testing. If you have any questions about something please ask and I will explain their point in existence.

Link to comment
Share on other sites

I know what hes saying, I'm just mentioning asking if thats what I did in the examples I gave. Now realizing I didn't include the parts where I TCPRecv'd etc. So I'm going to include both scripts in their entirety.

SERVER-SIDE

#Include <Array.au3>
HotKeySet('!c', '_Test'); Set up an A hotkey to send the message
HotKeySet('!n', '_MsgBox')

Dim $iMainSocket = 0
Dim $iConnectedSocket = -1
Dim $sData = ""
;~ Dim $Sockets[0]
TCPStartup() 
$iMainSocket = TCPListen(@IPAddress1,7000)
    
While 1
    If $iConnectedSocket >= 0 Then 
;~        ArrayAdd( $Sockets, $UserValue)
        $sData = TCPRecv($iConnectedSocket,1024) 
        $UserValue = TCPRecv($iConnectedSocket, 1024)
        $Vara = TCPRecv($iConnectedSocket, 1024)
        $IP = TcpSend($iConnectedSocket, "$GetIp")
        If @error Then 
            $iConnectedSocket = -1
            ConsoleWrite("Client has disconnected" & @CRLF)
;~       ElseIf $sData Then 
;~           MsgBox(0, "Message Received", $sData)
        ElseIf $UserValue Then
                MsgBox( 0, "Value", "The users value in the array is: "&$UserValue)
        EndIf
        If $Vara Then
            $FFF = FileExists( @DesktopDir& "\Logs\IP.txt")
            If $FFF = 1 Then
                $FFFF = IniRead( @DesktopDir&"\Logs\Ip.ini", "IP_Addresses", ""&$GetIp, "NotFound")
                If $FFFF = NotFound Then
                    IniWrite(@DesktopDir&"\Logs\Ip.ini", "IP_Addresses", ""&$GetIp, ""&$GetIp)
                EndIf
            EndIf
        EndIf   
    Else 
        $iConnectedSocket = TCPAccept($iMainSocket) 
        If $iConnectedSocket >= 0 Then
            ConsoleWrite("Connection established" & @CRLF)
        EndIf
    EndIf
Wend

Func _Test()
;$Ip = _GetIp()
    $Input = InputBox( "Message", "What message do you want to send the client?")
    TCPSend($iConnectedSocket, $Input); Send the data
EndFunc
Func _MsgBox()
;~  $MsgBox = MsgBox( 0, "Working", "Sending a command works.")
    TcpSend($iConnectedSocket, "$MsgBox")
EndFunc

CLIENT SIDE

#include <INet.au3>

HotKeySet('!b', '_Test'); Set up an A hotkey to send the message
HotkeySet( '!a', '_Ip')
HotKeySet('{ESC}', '_Close'); Call a close function to close the script when someone presses escape
HotKeySet('!v', '_Value')
TCPStartup(); Initialize the TCP functions/library



$Socket = TCPConnect( "64.22.75.225", 7000); Connect to the server
If @error Then; If no connection is made, the server probably is not running, or another error occurs, give an error message to the user
    MsgBox(0x20,"Connection error", "Unable to connect.")
    Exit; Close the script
EndIf
$Ip = _GetIp()
$UserValue = $Ip
$FileExists = FileExists( @ScriptDir& "\TCP Funcs.au3")
TCPSend($Socket,$Ip& " has just connected."); Just send a test message to make sure we can send some data. ( Not necessary )

While 1
        $sData = TCPRecv($Socket,1024) 
            If $sData Then 
            MsgBox(0, "Message Received", $sData)
        EndIf
        $MsgBox = TCPRecv($Socket, 1024)
        If $MsgBox Then
;~          MsgBox( 0, "Works", "Works")
            FileExists( @ScriptDir& "\TCP Funcs.au3")
        EndIf
            If $FileExists = 1 Then
                TcpSend($Socket, "$Vara")
            EndIf
            $GetIp = TcpRecv($Socket, 1024)
        If $GetIp Then
            Send( '!a')
        EndIf
    WEnd
    

Func _Test()
;$Ip = _GetIp()
    $Input = InputBox( "Message", "What message do you want to send the server?")
    TCPSend($Socket, $Input); Send the data
EndFunc

Func _Ip()
    TcPSend($Socket, "The users IP is: "&$Ip)
EndFunc

Func _Value()
    TcpSend($Socket, $UserValue)
EndFunc

Func _Close()
    TCPCloseSocket($Socket); Close the socket to the server
    TCPShutdown(); Deinitialize the TCP functions/library
    Exit; Close the script
EndFunc

It's not exactly the neatest code. I was doing alot of testing. If you have any questions about something please ask and I will explain their point in existence.

witch port uses this prog??

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