Jump to content

Tcp server If $TCPRecv


Recommended Posts

Hey guys Im not sure where I am going wrong 

I am trying to create a tcp server for my computer so that I can use a android app like this one 

https://play.google.com/store/apps/details?id=udpcontroller.nomal

to sent tcp messages to start programs

I got as far as recieve the commands from my phone 

but I am having trouble with the if statements they seem to do nothing

here is my server

#include <GUIConstantsEx.au3>


TCPStartup()
$TCPListen = TCPListen(@IPAddress1, 5700)

$INIFile = "Server.ini"

If FileExists ($INIFile) = 0 Then
    Local $Button_1, $Button_2, $msg
    GUICreate("Setup") ; will create a dialog box that when displayed is centered


   $Button_1 = GUICtrlCreateButton("Apply", 10, 325, 210)
   $Commandinput1 = GUICtrlCreateInput("Command1", 10, 10, 100)
   $Commandinput2 = GUICtrlCreateInput("Command2", 10, 45, 100)
   $Commandinput3 = GUICtrlCreateInput("Command3", 10, 80, 100) 
   $Commandinput4 = GUICtrlCreateInput("Command4", 10, 115, 100)
   $Commandinput5 = GUICtrlCreateInput("Command5", 10, 150, 100)
   $Commandinput6 = GUICtrlCreateInput("Command6", 10, 185, 100)
   $Commandinput7 = GUICtrlCreateInput("Command7", 10, 220, 100)
   $Commandinput8 = GUICtrlCreateInput("Command8", 10, 255, 100)
   $Commandinput9 = GUICtrlCreateInput("Command9", 10, 290, 100)
   $Executeinput1 = GUICtrlCreateInput("Execute1", 120, 10, 100)
   $Executeinput2 = GUICtrlCreateInput("Execute2", 120, 45, 100)
   $Executeinput3 = GUICtrlCreateInput("Execute3", 120, 80, 100) 
   $Executeinput4 = GUICtrlCreateInput("Execute4", 120, 115, 100)
   $Executeinput5 = GUICtrlCreateInput("Execute5", 120, 150, 100)
   $Executeinput6 = GUICtrlCreateInput("Execute6", 120, 185, 100)
   $Executeinput7 = GUICtrlCreateInput("Execute7", 120, 220, 100)
   $Executeinput8 = GUICtrlCreateInput("Execute8", 120, 255, 100)
   $Executeinput9 = GUICtrlCreateInput("Execute9", 120, 290, 100)
    GUISetState() ; will display an  dialog box with 2 button

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
             Case $msg = $Button_1
                $Command1 = GUICtrlRead( $Commandinput1)
                $Command2 = GUICtrlRead( $Commandinput2)
                $Command3 = GUICtrlRead( $Commandinput3)
                $Command4 = GUICtrlRead( $Commandinput4)
                $Command5 = GUICtrlRead( $Commandinput5)
                $Command6 = GUICtrlRead( $Commandinput6)
                $Command7 = GUICtrlRead( $Commandinput7)
                $Command8 = GUICtrlRead( $Commandinput8)
                $Command9 = GUICtrlRead( $Commandinput9)
                $Execute1 = GUICtrlRead( $Executeinput1)
                $Execute2 = GUICtrlRead( $Executeinput2)
                $Execute3 = GUICtrlRead( $Executeinput3)
                $Execute4 = GUICtrlRead( $Executeinput4)
                $Execute5 = GUICtrlRead( $Executeinput5)
                $Execute6 = GUICtrlRead( $Executeinput6)
                $Execute7 = GUICtrlRead( $Executeinput7)
                $Execute8 = GUICtrlRead( $Executeinput8)
                $Execute9 = GUICtrlRead( $Executeinput9)
                IniWrite($INIFile,"Commands","Command1",$Command1)
                IniWrite($INIFile,"Commands","Command2",$Command2)
                IniWrite($INIFile,"Commands","Command3",$Command3)  
                IniWrite($INIFile,"Commands","Command4",$Command4)
                IniWrite($INIFile,"Commands","Command5",$Command5)
                IniWrite($INIFile,"Commands","Command6",$Command6)
                IniWrite($INIFile,"Commands","Command7",$Command7)
                IniWrite($INIFile,"Commands","Command8",$Command8)
                IniWrite($INIFile,"Commands","Command9",$Command9)
                IniWrite($INIFile,"Execute","Execute1",$Execute1)
                IniWrite($INIFile,"Execute","Execute2",$Execute2)
                IniWrite($INIFile,"Execute","Execute3",$Execute3)
                IniWrite($INIFile,"Execute","Execute4",$Execute4)
                IniWrite($INIFile,"Execute","Execute5",$Execute5)
                IniWrite($INIFile,"Execute","Execute6",$Execute6)
                IniWrite($INIFile,"Execute","Execute7",$Execute7)
                IniWrite($INIFile,"Execute","Execute8",$Execute8)
                IniWrite($INIFile,"Execute","Execute9",$Execute9)
                Exit
        EndSelect
    WEnd
   EndIf

$1Command = IniRead($INIFile,"Commands","Command1","error")
$2Command = IniRead($INIFile,"Commands","Command2","error")
$3Command = IniRead($INIFile,"Commands","Command3","error")
$4Command = IniRead($INIFile,"Commands","Command4","error")
$5Command = IniRead($INIFile,"Commands","Command5","error")
$6Command = IniRead($INIFile,"Commands","Command6","error")
$7Command = IniRead($INIFile,"Commands","Command7","error")
$8Command = IniRead($INIFile,"Commands","Command8","error")
$9Command = IniRead($INIFile,"Commands","Command9","error")
$1Execute = IniRead($INIFile,"Execute","Execute1","error")
$2Execute = IniRead($INIFile,"Execute","Execute2","error")
$3Execute = IniRead($INIFile,"Execute","Execute3","error")
$4Execute = IniRead($INIFile,"Execute","Execute4","error")
$5Execute = IniRead($INIFile,"Execute","Execute5","error")
$6Execute = IniRead($INIFile,"Execute","Execute6","error")
$7Execute = IniRead($INIFile,"Execute","Execute7","error")
$8Execute = IniRead($INIFile,"Execute","Execute8","error")
$9Execute = IniRead($INIFile,"Execute","Execute9","error")

Do
$TCPAccept = TCPAccept($TCPListen)
Until $TCPAccept <> -1

Do
$TCPRecv = TCPRecv($TCPAccept, 1000000)
Until $TCPRecv <> ""


If $TCPRecv = $1Command Then
   Run($1Execute)
ElseIf $TCPRecv = $2Command Then
   Run($2Execute)
ElseIf $TCPRecv = $3Command Then
   Run($3Execute)
ElseIf $TCPRecv = $4Command Then
   Run($4Execute)
ElseIf $TCPRecv = $5Command Then
   Run($5Execute)
ElseIf $TCPRecv = $6Command Then
   Run($6Execute)
ElseIf $TCPRecv = $7Command Then
   Run($7Execute)
ElseIf $TCPRecv = $8Command Then
   Run($8Execute)
ElseIf $TCPRecv = $9Command Then
   Run($9Execute)
ElseIf  $TCPRecv = "" Then
   MsgBox(0, "Server", "Client sent a unknown command" &  $TCPRecv)
EndIf

Please help

PS. I cant reply to my own topics

So if you could maybe PM me

Link to comment
Share on other sites

Hi,

Your code is very dirty, have you tried the helpfile examples from the latest autoit beta?

Second thing is that your script will only receive one data (and not sure based on its size that you will get the full of it), you need to put a loop before your 2nd "Do" until the end of your script.

Br, FireFox.

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