Jump to content
Sign in to follow this  
Kip

TCP UDF, Event driven!

Recommended Posts

so what should I do now?

replace: _TCP_Server_Create(88, @IPAddress1); A server. Tadaa!

with: _TCP_Server_Create(88, '0.0.0.0'); A server. Tadaa!

??

or something you said with DynDNS (although I don't know what this is..) btw I have SpeedTouch 580

Share this post


Link to post
Share on other sites

i'd like to get past a little problem i have.

Client: *Disconnects*

Server: "huh?.. who did we just drop?"

So far i can only think of dropping the ip in an array upon connection, and make it run through the _TCP_Server_ClientList() when anyone disconnects...

or is there some other way i haven't discovered?

Share this post


Link to post
Share on other sites

nice! :D cool... but ;) conflict with _ArrayDisplay()..

#include "TCP.au3"
#include <array.au3>
Global $Test[2][2]
_TCP_Server_Create(88, "192.168.0.20")
_TCP_RegisterEvent($TCP_NEWCLIENT, "NewClient") ;or $TCP_DISCONNECT or $TCP_RECEIVE...

While 1
    Sleep(200)  
WEnd

Func NewClient($hSocket, $iError)
; do something

$Test[1][0]=$hSocket
_ArrayDisplay($Test) ; // list liew not draw..
EndFunc

ver au3 3.2.13.7

Will be good if you fix it.. ;)

thx!

Edited by Odin

Share this post


Link to post
Share on other sites

Hey,

Because people always ask how to create a TCP client/server, and then (if they get it) don't know how to make it multi client,

I simplified it.

It's event driven, so you don't have to manualy check everything.

Just checked out your version 2 and I have to say that it's very impressive. It's much more efficient than what I've been doing, and I'm retooling all my TCP-aware scripts to take advantage of it.

I did find a few design factors that can contribute to memory leaks, however. I have a script which has to frequently open and close one or more client connections, and every time _TCP_Client_Create is called, AutoIt allocates a little more RAM which it does not release when _TCP_Client_Stop is called. These seem to be causing the problems:

- TCPStartup() is called everytime _TCP_Client_Create or _TCP_Server_Create runs. This allocates memory each time it is run which can only be released by calling TCPShutdown(). The AutoIt help file warns about this. I think it would be best to let the user call TCPStartup() themselves before calling any of your functions.

- Likewise, you create a GUI window to receive messages each time _TCP_Client_Create or _TCP_Server_Create runs:

CODE
Local $hNotifyGUI = GUICreate("Kip's TCP UDF")
_TCP_Client_Stop and _TCP_Server_Stop should run corresponding GuiDelete() commands to avoid memory leaks.

- Many of Zatorg's functions (_ASock*) open a handle to a DLL that never gets closed:

CODE
If $hWs2_32 = -1 Then $hWs2_32 = DllOpen( "Ws2_32.dll" )
Then another handle is opened the next time one of the functions runs, which is also never closed. It makes more sense to me to just open one handle to the DLL and define it globally within the UDF:

CODE
Global $hWs2_32 = DllOpen( "Ws2_32.dll" )

There may have been some specific functionality you intended by your design that I'm just overlooking. If so, please let me know! Overall everything looks fantastic and I'm just hoping to help you increase its efficiency. Thanks for reading!

Share this post


Link to post
Share on other sites

Very nice Kip.

Although for me, (both client and server) stick around 85 % of CPU usage respectively.

Hopefully there is a fix for this. :P

Try adding a Sleep(100) inside the main loop in each script.

Share this post


Link to post
Share on other sites

Hi!!!

just thought of an odd idea for your code :mellow:

This idea involves a CLIENT that will be on all the time and a server that will only be on somtimes.

So what i need to do is use the client to keep trying to connect to the server (even when its offline)

Now i cant actually think of a way to do this as theres no way to Poll to see if the server is online before attempting to connect.

Any ideas?


Click here for the best AutoIt help possible.Currently Working on: Autoit RAT

Share this post


Link to post
Share on other sites

Yay! This is nice!

So, if I wanted to use my external IP: which is 71.71.... how can I use this so people, anyone in the world can connect to my server on my computer? With @IPAddress1 is only allowed on my network.

Share this post


Link to post
Share on other sites

if the server creates a socket on @IPAddress1, everybody in the world can acces it. Just make sure you have the right ports opened.

Maybe where you are at but @IPAddress1 on my computer returns 192.168.0.100, and only people in my network can access it. I have to set up my router to port forwarding incoming connections from my WAN ip to my LAN ip.

Share this post


Link to post
Share on other sites

Maybe where you are at but @IPAddress1 on my computer returns 192.168.0.100, and only people in my network can access it. I have to set up my router to port forwarding incoming connections from my WAN ip to my LAN ip.

Yeah, from what I thought I thought you had to have your external IP I think, or internal the one that is not 192.168.1.101 (or whatever your last 3 digits are) So manadar, how can I forward those incoming connections? I know how to access my router, but what port do I forward.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...