Jump to content

[Class] Simple TCP with OOP


matwachich
 Share

Recommended Posts

one question,

can u see any problem if the "client" part is running and if the user is issueing a reboot or shutdown, does the client understand that tcpip and stuff is closeing down on him?

Sorry for me crappy english and programming skills :D

what i want to know is if the client part would generate an error or if it just unload nicley?

Link to comment
Share on other sites

If you disconnect the electrical alimentation of your computer, of cours it will not close cleanely, but the only problem is that: it's possible (and i say possible) that the server will not be notified of the disconnection of the client.

If the computer runing the client is shuted down cleanly, then every thing will be fine, the client will free all ressources and shutdown normally, and the server will be notified of the disconnection

Ciao!

Link to comment
Share on other sites

ok thx, i notice that some clients (older hardware) do generate a windows error like (memory could not be written error) CH-Agent.exe (witch is my client) but only on reboot or shutdown and only sometimes. this dosent really matter becose its only during that circumstance.

i have no ide how to tackle it sence it only points to a memory adress and its not really importend in this case..

right now i add the row belove to try get the error go away

"C:windowsCH-Agent.exe /StdErrorOut" <<-- is this right? dident really find any dokumentations or example on this?

or should i do something like "C:windowsCH-Agent.exe /StdErrorOut >null"

//Thx Lasse

PS

I think the error could come from a crypted string i send up to a webserver like post, i do this every 2 min and not with ur great code but with winhttp, but this is just a guess.

Edited by lgvlgv
Link to comment
Share on other sites

  • 8 months later...

Yo.

I'm trying to convert to this UDF. Right now I seem to be missing the include files. The orriginal post in this thread says they're in the zip. I got a .rar rather than a zip for one thing, and the only thing in that .rar are server.AU3 and client.AU3.and a docs folder. Any tips?

Thanks

Link to comment
Share on other sites

Explaining what it is you're missing would be a great way to start.

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

Link to comment
Share on other sites

AutoItObject can be found here.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thanks.

I've gotten hold of the Verso autoit object files needed and have constructed a server. Now I am working on the client, and I'm stumped. All I can think of to do is to give the basic idea and see if anyone can jog my brain. From my point of view it kind of looks like I can't use this client but I'm sure I can once I know how to start.

Basically the client will load the port and IP from an .ini when it is started. It should try to connect using that immediately on load. If the connection fails or the user supplies a different IP or port that makes the current connection invalid it needs to try to connect using the new settings. It should always try to reconnect if the connection is lost or if the attempt to connect fails. The outcome is that the client should always be connected when it is running unless the server isn't available or there is a connection problem or the IP or port is typed wrong etc.

The version I had before I tried this new one here would disconnect the client when the user started to edit the IP address field which was always on screen even while connected and would try to reconnect again when it decided the user had typed a complete IPv4 address. This worked pretty nicely but there could be issues like the user may have been going to put two more digits on the IP address when the loop came around and decided the data in the input field was an IPv4 address, which it may have been. Think 184.84.84.1 , could have been .184 on the end. That and the user could not try a host name. I will be dropping this idea but I do want the client to do a great job at maintaining it's connection indefinitely and if the connection fails I want it to paciently lounge around and make periodic attempts to reestablish the connection indefinitely.

Can I have some help with how to do this with the object? I'm stumped on how and where to construct the class, and how to modify it and handle things properly when the configuration is changed. I also plan to support use of different passwords, but I hope that if I can get some help with what I've asked about I'll be able to figure the rest out.

I can run a function in my main loop that would make it connect, but the class is constructed with the port and IP specified. How to try next time using the new configuration? The mini client just tries to connect once and if that fails it closes. That's definitely not what I need to do. My client will sit with certain controls grayed out while it makes attempts to connect.

I'll shut up now because I'm afraid if I try to say anything else I'll start to confuse myself. I could add in snipets from my main code but I haven't really done anything with it yet because I haven't an idea how to even start so there is nothing to show.

Thank you all very much, especially the one who wrote this class.

Link to comment
Share on other sites

i will propose a patch to both your TCP project both with and without OOP

Current Version:

; Check buffer ok
$tmp = __TCPClient_CheckBuffer($iClient)
If IsArray($tmp) Then
For $elem In $tmp
If $__TCPClient_Clients[$iClient][$__TCPc_CB_RECV] Then _
     Call($__TCPClient_Clients[$iClient][$__TCPc_CB_RECV], $iClient, $elem)
Next
$__TCPClient_Clients[$iClient][$__TCPc_BUFFER] = ""  ;<-----------------------------------------------------
; ---
EndIf

Proposed:

; Check buffer ok
$tmp = __TCPClient_CheckBuffer($iClient)
If IsArray($tmp) Then
$__TCPClient_Clients[$iClient][$__TCPc_BUFFER] = "" ;<-----------------------------------------------------
For $elem In $tmp
     If $__TCPClient_Clients[$iClient][$__TCPc_CB_RECV] Then _
Call($__TCPClient_Clients[$iClient][$__TCPc_CB_RECV], $iClient, $elem)
Next
; ---
EndIf

if ever the user who use that UDF call process within the Callback _TCP_Recv() he start receiving duplicate data

That patch should be apply to "timeout check" also, saving the buffer into a temp val and doing the binary count with that temp val, delete the real buffer data before the callback happen :)

Thanks you very much i appreciate that UDF very much :)

GreenseedMCSE+I, CCNA, A+Canada, QuebecMake Love Around You.

Link to comment
Share on other sites

Anybody got an example client I can look at that is able to change connection details and reconnect while the application is running? That's what I was talking about in my last pot. I cant figure out how to connect with new details after the client is already running. The example mini client I got with this just connects on startup and if it fails to connect closes.

Link to comment
Share on other sites

  • 2 months later...

I have been using this tcp server client script for a year now and I haven't had any problem.

everything runs fine.

the problem I found is that it seems to convert foreign characters to question marks "?". when I try to copy some arabic characters from the character map and send them, I always receive a string of question marks.

how to fix this issue? I need to use this script with asian characters.

Link to comment
Share on other sites

  • 1 year later...

Something must have changed in latest AutoIT, non of my old scripts work, only get Connection lost right away after connect?

The compiled work but not if i try to make a new, not even the examples included work ?

Anyone knows why?

Link to comment
Share on other sites

Here is the fix.

In server.au3 search for:

$sRecv = TCPRecv($__TCPServer_Sockets[$i][0], $oSelf.max_recv_len)
If @error Then

And replace it with:

$sRecv = TCPRecv($__TCPServer_Sockets[$i][0], $oSelf.max_recv_len)
If @error < -1 Then

In client.au3 search for:

Local $recv = TCPRecv($oSelf.socket, $oSelf.max_recv_len)
;ConsoleWrite($recv & " - @error = " & @error & " - @extended = " & @extended & @CRLF)
If @error Then ; Disconnected

And replace it with:

Local $recv = TCPRecv($oSelf.socket, $oSelf.max_recv_len)
;ConsoleWrite($recv & " - @error = " & @error & " - @extended = " & @extended & @CRLF)
If @error < -1 Then ; Disconnected

For more information check this out:

'?do=embed' frameborder='0' data-embedContent>>

Link to comment
Share on other sites

Here is the fix.

In server.au3 search for:

$sRecv = TCPRecv($__TCPServer_Sockets[$i][0], $oSelf.max_recv_len)
If @error Then

And replace it with:

$sRecv = TCPRecv($__TCPServer_Sockets[$i][0], $oSelf.max_recv_len)
If @error < -1 Then

In client.au3 search for:

Local $recv = TCPRecv($oSelf.socket, $oSelf.max_recv_len)
;ConsoleWrite($recv & " - @error = " & @error & " - @extended = " & @extended & @CRLF)
If @error Then ; Disconnected

And replace it with:

Local $recv = TCPRecv($oSelf.socket, $oSelf.max_recv_len)
;ConsoleWrite($recv & " - @error = " & @error & " - @extended = " & @extended & @CRLF)
If @error < -1 Then ; Disconnected

For more information check this out:

'?do=embed' frameborder='0' data-embedContent>>

 Thx :)  will try  it as soon as i get back from Thailand :)

Link to comment
Share on other sites

  • 3 weeks later...

Here is the fix.

In server.au3 search for:

$sRecv = TCPRecv($__TCPServer_Sockets[$i][0], $oSelf.max_recv_len)
If @error Then

And replace it with:

$sRecv = TCPRecv($__TCPServer_Sockets[$i][0], $oSelf.max_recv_len)
If @error < -1 Then

In client.au3 search for:

Local $recv = TCPRecv($oSelf.socket, $oSelf.max_recv_len)
;ConsoleWrite($recv & " - @error = " & @error & " - @extended = " & @extended & @CRLF)
If @error Then ; Disconnected

And replace it with:

Local $recv = TCPRecv($oSelf.socket, $oSelf.max_recv_len)
;ConsoleWrite($recv & " - @error = " & @error & " - @extended = " & @extended & @CRLF)
If @error < -1 Then ; Disconnected

For more information check this out:

'?do=embed' frameborder='0' data-embedContent>>

 

Seems to work for the connection, but the disconnect dosent work, guess the auto disconnect also have to be modifyed.

//Lasse

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

×
×
  • Create New...