Sign in to follow this  
Followers 0
LuigiMario

Chat script freezes

7 posts in this topic

I'm trying to make an autoit script which connectso to an Italian irc server. It's quite difficult and I am new to autoit.

So, I made a script which is able to answer to ping requests from the server and to get query msgs, and I decided to make a gui for it....

But the gui is freezing, and I don't know why.

Here's the code I wrote so far, it is commented in English, so please help me with it! (And feel free to suggest how to better it, because I imagine it's really crappy :whistle: )

CODE

AutoItSetOption ( "tcptimeout",100000)

Opt("GUIOnEventMode", 1)

#include <inet.au3>

#include <Misc.au3>

#include <GUIConstants.au3>

$myip = _GetIP ( )

TCPStartUp()

$socket = TCPConnect ("89.96.189.218",6667) ; <- server ip and port, change it to another if you can't connect to it

If $socket = -1 Then

Beep("1000")

Consolewrite("Errore")

Exit

endif

;sleep("3000")

Csend($socket,"NICK " & "autest" & @cr)

Csend($socket,"USER autest autest 8 : Testing around" & @cr)

$data = TCPRecv ($socket, 20)

$msg = ""

#Region gui

$channel = GUICreate("Chat", 601, 266, 241, 146, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_OVERLAPPEDWINDOW,$WS_TILEDWINDOW,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_BORDER,$WS_CLIPSIBLINGS))

$rcvd = GUICtrlCreateEdit("", 0, 0, 600, 235, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))

GUICtrlSetData(-1, "(Test)")

$inputbox = GUICtrlCreateInput("", 0, 240, 536, 21)

$sendbtn = GUICtrlCreateButton("Invia", 540, 240, 60, 25, $BS_DEFPUSHBUTTON, $WS_EX_CLIENTEDGE)

GUISetState(@SW_SHOW)

#EndRegion

while $data <> "" ; <- I bet this while can be different and better, but I have no idea on how do such a thing.

;-----------------------------------------> Read data & split it into readable msgs.

if Stringinstr($data,@cr) = 0 Then

$msg = $msg & $data

;It's not the whole string

else

$gettingdata = StringSplit($data,@cr)

$msg = $msg & $gettingdata[1]

;----------------------------------------> Now we have the message! -> $themsg

$themsg = StringStripWS($msg,1)

consolewrite("RCV> " & $themsg & @crlf)

;----------------------------------------> Let's work with it: MESSAGE FUNCTIONS

;-----------------------------------------------------------------------------------------> I just noticed... If in the message there are two "cr"s, I would lost half of the message from the server... Am I right?

$token32 = StringSplit(stringleft($themsg,100)," ")

$tokenpunti = StringSplit(stringleft($themsg,100),":")

if ($tokenpunti[0] >= 2) Then $tokennick = StringSplit($tokenpunti[2],"!")

if ($token32[0] >= 2) Then

if $token32[1] = "PING" Then

csend($socket,"PONG " & $token32[2]) ; --------------> Don't kill me, I'm still here!

elseif ($token32[2] = "PRIVMSG") Then

if (StringLeft(StringTrimLeft($themsg,StringLen($tokenpunti[2]) + stringlen($tokenpunti[1]) + 2),1) = "") Then

$tokenctcp = StringSplit($themsg,"")

IF (Stringinstr($tokenctcp[2]," ") <> 0) Then

$tokenctcp = StringSplit($tokenctcp[2]," ")

$ctcpspazio = 1

endif

Csend($socket,"NOTICE " & $tokennick[1] & " :" & _iif($ctcpspazio = 1,$tokenctcp[1],$tokenctcp[2]) & "meh" & @cr)

else

;msgbox(0,"MessenChat - Nuovo messaggio","Nuovo messaggio da " & $tokennick[1] & ":" & @crlf & StringTrimLeft($themsg,StringLen($tokenpunti[2]) + stringlen($tokenpunti[1]) + 2))

GUICtrlSetData ( $rcvd, $tokennick[1] & " writes:" & @crlf & StringTrimLeft($themsg,StringLen($tokenpunti[2]) + stringlen($tokenpunti[1]) + 2) & @crlf,default)

endif

endif

endif

$msg = ""

$data = ""

$gettingdata = ""

$themsg = 0

$ctcpspazio = 0

endif

GuiSetState(@sw_show)

sleep("100") ; <- this SHOULD prevent the gui from freezing, and it actually works only when the server sends you a lot of data.

$data = tcprecv($socket,20)

wend

consolewrite("Got blank string. Blarrrgh!")

#region Functions

func csend($socket,$data)

Local $chc

$chc = TcpSend($socket,$data)

if ($chc = 0) then

Consolewrite("! ERRORE - IMPOSSIBILE INVIARE: " & $data & @crlf) ; --> Something went wrong, and the message couldn't be sent

Else

ConsoleWrite("SNT> " & $data & @crlf)

endif

EndFunc

Share this post


Link to post
Share on other sites



Put Opt("TrayIconDebug", 1) at the top of your script and when your GUI freezes put your mouse over the tray icon and it will tell you what line of code your script is currently running.

If you still can't get it post what the trayicondebug is saying and that will give everyone a better idea of where to look for the error.


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Put Opt("TrayIconDebug", 1) at the top of your script and when your GUI freezes put your mouse over the tray icon and it will tell you what line of code your script is currently running.

If you still can't get it post what the trayicondebug is saying and that will give everyone a better idea of where to look for the error.

If you run your code with a much smaller tcp timeout setting (say 1000 ms), you may get an error about an empty string in the console. (I did! :whistle:)

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

If you run your code with a much smaller tcp timeout setting (say 1000 ms), you may get an error about an empty string in the console. (I did! :whistle:)

Excuse me, I don't get the point of your message... Are you saying that I should change the tcp timeout setting?

@Someone: Thanks, I'll try!

Edit: It seems to stop on the "sleep(100)" command... But the question is: why?

Edit2: Once that line is commented-out, it freezes on the next one: $data = tcprecv($socket,20), but the question remains; why?

Edited by LuigiMario

Share this post


Link to post
Share on other sites

Excuse me, I don't get the point of your message... Are you saying that I should change the tcp timeout setting?

Yes... If the tcp transmission times out, you will have to wait 100 seconds for your error with the big 100000 timeout. If you change it to 1000 or something for testing, you have to wait shorter for the error while testing, and see earlier where the problem is, if it is or isn't in the tcp transmission :whistle:


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

The timeout is so big because the server waits a random time before it starts to send you messages. This time should be needed by the server for a lookup on your ip, and to scan some ports to check if you're running an open proxy or things like that.

If the timeout is smaller, it automatically crashes at that moment. If I put a sleep() function to make the script wait for about 50 seconds before reading anything from the socket, it crashes immediately after, because the server doesn't send you data so fast.

Additionally, if you're not on a channel, most of the time you won't get anything from the server. So, yes, that big timeout is really needed (well, I think!).

Thankyou for your help. :whistle:

Now, I figured out that the line that freezes is the "$data = TCPRecv($socket,20)" BEFORE the loop (the line before the dialog region start) or the one IN the loop... Maybe because the socket doesn't recieve anything?

Any ideas...?

Edited by LuigiMario

Share this post


Link to post
Share on other sites

SadBunny, you were right. A bit of script editing, and a smaller timeout, and everythings works like a charm.

But I bet I'll have more problems in the future, and come back here for help. :whistle:

Thanks to everyone.

Share this post


Link to post
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
Sign in to follow this  
Followers 0