Jump to content
Sign in to follow this  
tsolrm

AdlibRegister

Recommended Posts

tsolrm

I've got a function that get's called every 5-10 seconds. As soon as it does - the program starts lagging. Is the problem in the function itself or...?

Function:

AdlibRegister ("Connect", 5000)

Func Connect ()
If $TCPConnect = -1 Then
  $TCPConnect = TCPConnect ("ip", port)
  If not @error Then
   If $State = 1 Then
    $title=WinGetTitle ("NAME - NAME1")
    $title = StringSplit ($title, " - ", 1)
    If not @error and $title [0] > 1 Then
     $nick=$title[2]
     TCPSend ($TCPConnect, "nick="&$nick)
    EndIf
   Else
    TCPSend ($TCPConnect, "closed")
   EndIf
  EndIf
EndIf
EndFunc

Share this post


Link to post
Share on other sites
water

I'm sure it's the function. The main script is paused every 5 seconds to run the function and waits till the function has finished.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
tsolrm

By the way - this happens when the server is offline - so when TCPConnect = -1. Don't make any sense, it should assume that TCPConnect = -1 and move on

Share this post


Link to post
Share on other sites
BrewManNH

What your function does is it checks the $TCPConnect variable and if you're not connected ($TCPConnect = -1), it tries to connect; if it can't connect it's going to sit there waiting until it times out.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
tsolrm

How do i make it not do that?

Share this post


Link to post
Share on other sites
tsolrm

TCPTimeout Defines the time before TCP functions stop if no communication.

Time in milliseconds before timeout (default=100).

The default is 100 miliseconds so it shouldn't lag at all

Share this post


Link to post
Share on other sites
BrewManNH

There's a bug report on the Tracker reporting that the option for TCPTimeout doesn't seem to do anything, looks like it takes about 20 seconds before it times out and throws an error message back.

EDIT: I found that JScript started, and ProgAndy added to, that has an alternate TCPConnect that includes a timeout parameter that might work better for you than the built-in TCPConnect.

Edited by BrewManNH
  • Like 1

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
tsolrm

There's a bug report on the Tracker reporting that the option for TCPTimeout doesn't seem to do anything, looks like it takes about 20 seconds before it times out and throws an error message back.

EDIT: I found that JScript started, and ProgAndy added to, that has an alternate TCPConnect that includes a timeout parameter that might work better for you than the built-in TCPConnect.

I think that worked! I don"t know what the function does but i've plugged it in and it seems to not slow down anything. Thank you

Share this post


Link to post
Share on other sites
tsolrm

No it didn't. _TCPConnect returns values other than -1 even when the server is offline.

What I am trying to do is this:

I want my script every so often to try and connect to the server. Every 60 seconds for example. If the server is offline then try again in 60. Whats the best way to do this?

Share this post


Link to post
Share on other sites
BrewManNH

What is it returning other than -1 when it's offline?

Because when I run it with TCPConnect or with _TCPConnect from the link, I'm getting -1 on a non-existant server and it returns, for me at least, in under a millisecond. This is on Windows 7 x64, trying to "connect" to one of yahoo's webserver IP addresses.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
tsolrm

It returns 468 for me when the server is offline

The server is offline

$ip="ip"

$port=port

$timeout=500

$TCPConnect = _TCPConnect ($ip, $port, $timeout)

ConsoleWrite ($TCPConnect&@CRLF)

The console displays 468

Edited by tsolrm

Share this post


Link to post
Share on other sites
tsolrm

I've opened my current connections using TCPView

Even though the server script is not running - this function connects to the port but the connection dissapears after 20 seconds. I'm not sure how is it doing it cos the server is not listening on that port.

Edited by tsolrm

Share this post


Link to post
Share on other sites
BrewManNH

Please post your script so that we can figure out where it's going wrong, because I can't duplicate your problem using anything I've tried.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
tsolrm

Maybe because you haven't opened your port for listening and haven't set up port forwarding.

$ip="ip"

$port=port

$timeout=500

$TCPConnect = _TCPConnect ($ip, $port, $timeout)

ConsoleWrite ($TCPConnect&@CRLF)

thats it basically. TCPConnect returns a value different to -1 because it does in fact connect to the port (for about 20 seconds or so) and then the connection is abandoned. I've checked this with TCPView

Share this post


Link to post
Share on other sites
BrewManNH

So it's not failing, it's connecting to the port that you have opened, it's just not telling you there's no server there.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
tsolrm

Yes. But this is useless because it thinks it has a connection when it really doesn't.

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  

×