Question

I'm creating a 'chat' client and server in AutoIT. The server currently looks like

i.imgur.com/2XXgeSn.png

And the client currently looks like

i.imgur.com/HpMy1hY.png

At the moment the communication between the two is perfect, and I'm having no troubles, except that the close button on the server isn't working. The reason, is; is because the Do-Until loops I have running which are required to pickup incoming data are taking up thread1. I know AutoIT isn't multithreaded and with the Do-Until's constantly running, the GUI is pretty much blanked out. What can I do to fix this?

Server Code, Client Code

Was it helpful?

Solution

You could break out the checking for the form close into its own function, then call that function in your Do..Until loops. Copy of your server code below with those changes:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("VChat", 616, 438, 192, 124)
$Input1 = GUICtrlCreateInput("", 8, 8, 513, 25, $ES_READONLY)
$Button1 = GUICtrlCreateButton("Send", 528, 8, 75, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
$Edit1 = GUICtrlCreateEdit("", 8, 40, 593, 385, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, "")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

Func CheckForClose()
  $nMsg = GUIGetMsg()
  Switch $nMsg
   Case $GUI_EVENT_CLOSE
      Exit
  EndSwitch   
EndFunc

Func retrieveData()
  Do
    Local $TCPAccept = TCPAccept($TCPListen)
    CheckForClose()
  Until $TCPAccept <> -1

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

  GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & $TCPRecv & @CRLF)
EndFunc

While 1
  retrieveData()
WEnd

Run(@ScriptFullPath)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top