Jump to content

TCPRecv


Ranmaru
 Share

Recommended Posts

Is it possible to make TCPRecv trigger an event?

I think having to manually check for new TCP messages with TCPRecv is a bad method...

And there are events for AutoIt for tray and gui controls, so why not TCP or have I just not found these?

- Thanks for any info, Ran.

Link to comment
Share on other sites

You mean something like this?

;Put your other code before this
While 1
If TCPRecv($conn) Then
    If TCPRecv($conn) = "exit" Then
       Exit
   EndIf
EndIf
WEnd

If this is not what you mean, PM me. I'll show you one of my old codes that might help you.

No this is manual checking.. Like I said I'm looking for an EVENT. A function that is automatically triggered when receiving messages so the script doesn't have to keep on listening to them and can do something else instead.

Functions similiar to those of tray and gui controls..

GUICtrlSetOnEvent($hwnd, "function_name")

TrayCtrlSetOnEvent($hwnd, "function_name")

Not sure if those are the right functions to use, then there's the Opt that has to be set first. I don't have ScITE open atm so nevermind if I didn't get them right, you know what I mean.

Edited by Ranmaru
Link to comment
Share on other sites

I doubt it will happen. Socket programming doesn't use events, it just uses buffers in every instance I have seen. You can pick up data, or you can let it pile up, but you have to read it yourself.

Events are used for ActionScript's XMLSockets (Basically these are just TCP sockets) that is used in Flash, works like a charm there.

/EDIT:

Your TCP messages sent using the XMLSockets are all in HEX and each message is terminated with the NULL char so that's how it knows when a message is complete, quite nice system they have. There could be a similiar option for AutoIt so you could manually set the terminating character.

Edited by Ranmaru
Link to comment
Share on other sites

Could also use adlibenable;

#include <String.au3>

TCPStartup()
$oSock = TCPConnect("", )
AdlibEnable("Recv", 1)

TCPSend($oSock, Hexit(""))

While 1
    Sleep(100)
WEnd

Func Recv()
    $oRecv = TCPRecv($oSock, 2045)
    If $oRecv <> "" Then
        ConsoleWrite($oRecv)
    EndIf
EndFunc

Func Hexit($oText)
    Return _HexToString(StringReplace($oText, " ", ""))
EndFunc

Thats what I use, But yeah, Not what you want.

# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

@all

The "AdlibEnable" is more or less the same as a While / Next loop with a sleep (250) in it.

The better way is to use the Socket Events from Windows :

Like this Socket Events

But unfortunately you will have to do through the DLLCall API's. It is not build into AU3.

regards

ptrex

Link to comment
Share on other sites

@all

The "AdlibEnable" is more or less the same as a While / Next loop with a sleep (250) in it.

The better way is to use the Socket Events from Windows :

Like this Socket Events

But unfortunately you will have to do through the DLLCall API's. It is not build into AU3.

regards

ptrex

Seems interesting I will probably take some time to get into this too later, thanks ptrex.

Zatorg posted this awhile back, I've been playing with it forever, and I love it. I'm making an old school MUD server with it currently, but it will work with anything.

Asynchronous sockets UDF

This is most usefull, thanks SkinnyWhiteGuy. :P

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...