Jump to content

_arraydisplay freezes


Recommended Posts

I am doing some testing while trying to write a server/client utility that will run autoit lines when i send it to the client or server. When i wanted to get the array for a list of commands to run.

I tested displaying an array with _arraydispay() in the received() function. I am using the tcp udf found on the forums.

the code below runs, but when it gets a message _arraydisplay() hangs

It doesn't hang if i run it outside of the received() function, now im using a function to call it _doarray(),

any ideas? or thoughts on why it is not working?

Server: runs the client after it starts

#include <GUIConstantsEx.au3>
#include "TCP.au3"
#include <array.au3>

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)
Global $sockclient

TrayCreateItem("Send")
TrayItemSetOnEvent(-1,"_Sendmsg")

TrayCreateItem("Gui")
TrayItemSetOnEvent(-1,"_CreateGui")

TrayCreateItem("")

$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"ExitScript")

TraySetState()

ToolTip("SERVER: Creating server...",10,30)

$hServer = _TCP_Server_Create(88); A server. Tadaa!

_TCP_RegisterEvent($hServer, $TCP_NEWCLIENT, "NewClient"); Whooooo! Now, this function (NewClient) get's called when a new client connects to the server.
_TCP_RegisterEvent($hServer, $TCP_DISCONNECT, "Disconnect"); And this,... this will get called when a client disconnects.

Run(@AutoItExe & ' /autoit3executescript ' &'"' & @ScriptDir &'\tcpclient.au3"')

While 1
WEnd

Func NewClient($hSocket, $iError); Yo, check this out! It's a $iError parameter! (In case you didn't noticed: It's in every function)
     Global $sockclient = $hSocket
     ToolTip("SERVER: New client connected."&@CRLF&"Sending this: Bleh!",10,30)

     _TCP_Send($hSocket, "Bleh!"); Sending: "Bleh!" to the new client. (Yes, that's right: $hSocket is the socket of the new client.)
    _TCP_RegisterEvent($hSocket, $TCP_RECEIVE, "Received"); Function "Received" will get called when something is received
     
EndFunc

Func Disconnect($hSocket, $iError); Damn, we lost a client. Time of death: @Hour & @Min & @Sec :P
     
     ToolTip("SERVER: Client disconnected.",10,30); Placing a tooltip right under the tooltips of the client.
     
 EndFunc
 
Func Received($hSocket, $sReceived, $iError); And we also registered this! Our homemade do-it-yourself function gets called when something is received.
         ToolTip("Send: We received this: "& $sReceived, 10,10); (and we'll display it)
         GUICtrlSetData($edit, $sReceived & @CRLF & GUICtrlRead($edit))
     EndFunc
     

Func ExitScript()
    Exit
EndFunc
Func _Sendmsg()
     $szData = InputBox("Data for client", @LF & @LF & "Enter data to transmit to the CLIENT:", "", "", "", "", 200, 500)
          ; We should have data in $szData... lets attempt to send it through our connected socket.
            TCPSend($sockclient, $szData)

          ; If the send failed with @error then the socket has disconnected
          ;----------------------------------------------------------------
            If @error Then exit
EndFunc
     
Func _CreateGui()
    Opt("GUICoordMode", 2)
    Opt("GUIResizeMode", 1)
    Opt("GUIOnEventMode", 1)
    Global $GOOEY
    Global $edit
    $GOOEY = GUICreate("My Server (IP: " & @IPAddress1 & ")", 300, 200)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_guiclose")
    $edit = GUICtrlCreateEdit("", 10, 10, 280, 180)
    GUISetState()
EndFunc

Func _guiclose()
     GUIDelete($GOOEY)
EndFunc

client: run from the server: holds the code that is erroring

#include <GUIConstants.au3>
#include <WindowsConstants.au3>

#include <string.au3>
#include <Misc.au3>
#include <file.au3>
#include "TCP.au3"
#include <array.au3>
     
Global $GOOEY
Global $edit
Global $recv
Global $msg

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)
Global $sockclient

TrayCreateItem("Send")
TrayItemSetOnEvent(-1,"_Sendmsg")

TrayCreateItem("Gui")
TrayItemSetOnEvent(-1,"_GuiCreate")

TrayCreateItem("")

$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"ExitScript")

TraySetState()

ToolTip("CLIENT: Connecting...",10,10)

$hClient = _TCP_Client_Create(@IPAddress1, 88); Create the client. Which will connect to the local ip address on port 88

_TCP_RegisterEvent($hClient, $TCP_RECEIVE, "Received"); Function "Received" will get called when something is received
_TCP_RegisterEvent($hClient, $TCP_CONNECT, "Connected"); And func "Connected" will get called when the client is connected.
_TCP_RegisterEvent($hClient, $TCP_DISCONNECT, "Disconnected"); And "Disconnected" will get called when the server disconnects us, or when the connection is lost.

While 1
;$szData = InputBox("Data for Server", @LF & @LF & "Enter data to transmit to the SERVER:")

          ; If they cancel the InputBox or leave it blank we exit our forever loop
;          If @error Or $szData = "" Then ExitLoop

          ; We should have data in $szData... lets attempt to send it through our connected socket.
;          TCPSend($hClient, $szData)

          ; If the send failed with @error then the socket has disconnected
          ;----------------------------------------------------------------
;          If @error Then ExitLoop

; just to keep the program running
WEnd
     
Func Connected($hSocket, $iError); We registered this (you see?), When we're connected (or not) this function will be called.
         
    If not $iError Then; If there is no error...
        ToolTip("CLIENT: Connected!",10,10); ... we're connected.
    Else; ,else...
        ToolTip("CLIENT: Could not connect. Are you sure the server is running?",10,10); ... we aren't.
    EndIf
EndFunc
     
     
Func _doarray()
        Local $avArray[10]

$avArray[0] = "JPM"
$avArray[1] = "Holger"
$avArray[2] = "Jon"
$avArray[3] = "Larry"
$avArray[4] = "Jeremy"
$avArray[5] = "Valik"
$avArray[6] = "Cyberslug"
$avArray[7] = "Nutster"
$avArray[8] = "JdeB"
$avArray[9] = "Tylo"

_ArrayDisplay($avArray, "$avArray set manually 1D")
EndFunc
Func Received($hSocket, $sReceived, $iError); And we also registered this! Our homemade do-it-yourself function gets called when something is received.
  ;MsgBox(0, "Client", "CLIENT: We received this: "& $sReceived); (and we'll display it)
    _doarray()
;GUICtrlSetData($edit, $sReceived & @CRLF & GUICtrlRead($edit))
;$recvarr = StringSplit(StringStripWS($sReceived, 7), ';|' & @CR)
;If UBound($recvarr) > 2 Then

;_ArrayDelete($recvarr, 0)
;for $var in $recvarr
;   msgbox(0, "array", $var)
;Next
;Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & $recvarr[1])
;EndIf
;run($sReceived)
EndFunc
     
Func Disconnected($hSocket, $iError); Our disconnect function. Notice that all functions should have an $iError parameter.
    ToolTip("CLIENT: Connection closed or lost.", 10,10)
EndFunc

Func ExitScript()
    Exit
EndFunc
Func _Sendmsg()
     $szData = InputBox("Data for Server", @LF & @LF & "Enter data to transmit to the SERVER:", "", "", "", "", 200, 500)
          ; We should have data in $szData... lets attempt to send it through our connected socket.
            TCPSend($hClient, $szData)

          ; If the send failed with @error then the socket has disconnected
          ;----------------------------------------------------------------
            If @error Then exit
        EndFunc
        
Func _GuiCreate()
    Opt("GUICoordMode", 2)
    Opt("GUIResizeMode", 1)
    Opt("GUIOnEventMode", 1)

    $GOOEY = GUICreate("My Server (IP: " & @IPAddress1 & ")", 300, 200)
    $edit = GUICtrlCreateEdit("", 10, 10, 280, 180)
    GuISetOnEvent($GUI_EVENT_CLOSE, "_guiclose")
    GUISetState()
EndFunc

Func _guiclose()
     GUIDelete($GOOEY)
EndFunc
Edited by Yeik
func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()
Link to comment
Share on other sites

The _ArrayDisplay() function creates a GUI, and it sets GuiOnEventMode = 0, then restores it to the previous condition. You are interrupting the _ArrayDisplay() function's GuiGetMsg() loop for event handling that is creating your own GUI with GuiOnEventMode = 1, which disables the _ArrayDisplay() GUI.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...