Jump to content

Opening a tcp socket for x seconds before closing?


Recommended Posts

Do
    $nTimer = TimerInit()

$nDiff = TimerDiff($nTimer)/ 1000
    ;if Round($ndiff,2) >= "5" Then
        ;msgbox(0,"Timer","Greater than or equal to 5. Number is - "&$ndiff)
        ;Exit
;EndIf

    $ConnectedSocket = TCPAccept($MainSocket)

    sleep(6000);its over 5 and still wont register
Until $ConnectedSocket <> -1 or Round($ndiff,2) < "5"

if i make it < "5" then it will work... why wont it work if i go > "5" ?

Edited by backstabbed

tolle indicium

Link to comment
Share on other sites

If i make it < "5" then it will work... why wont it work if i go > "5" ?

First off all these are what < and > actually do....

> Tests if the first value is greater than the second.

< Tests if the first value is less than the second.

So < 5 will make it test if the timer is less than 5, and > 5 will test if the timer is greater than 5.

So you want it to test if the timer is greater or equal to 5, correct? Try this:

TCPStartup ()
$MainSocket = TCPListen("127.0.0.1", 1234)
$nTimer = TimerInit()
Do
    $nDiff = TimerDiff($nTimer)/ 1000
    ;If Round($ndiff,2) >= "5" Then
    ;    msgbox(0,"Timer","Greater than or equal to 5. Number is - "&$ndiff)
    ;    ExitLoop
    ;EndIf
    $ConnectedSocket = TCPAccept($MainSocket)
    sleep(6000);its over 5 and still wont register
Until $ConnectedSocket <> -1 or Round($ndiff,2) >= "5"
Msgbox(0,"Timer","Greater than or equal to 5. Number is - "&$ndiff)

I added the bit at the top to make it work...

Hope it helps :)

Link to comment
Share on other sites

I already have teh sockets opened in my program im just adding this part to it, i know the tcp is opening, and all im just trying to get it to shutdown once the 5 second elapse has come.

Full function:

func _accept()


Dim $szIPADDRESS = @IPAddress1
Dim $nPORT = 1337
TCPStartUp()

$MainSocket = TCPListen($szIPADDRESS, $nPORT)

If $MainSocket = -1 Then 

        Exit
        EndIf

Dim $ConnectedSocket = -1



Do
    $nTimer = TimerInit()
    $nDiff = TimerDiff($nTimer)/ 1000
    ;If Round($ndiff,2) >= "5" Then
    ;    msgbox(0,"Timer","Greater than or equal to 5. Number is - "&$ndiff)
    ;    ExitLoop
    ;EndIf
    $ConnectedSocket = TCPAccept($MainSocket)
    sleep(6000);its over 5 and still wont register
Until $ConnectedSocket <> -1 or Round($ndiff,2) >= "5"
Msgbox(0,"Timer","Greater than or equal to 5. Number is - "&$ndiff)


; Get IP of client connecting
Dim $szIP_Accepted = SocketToIP($ConnectedSocket)

Dim $recv

While 1



    $recv = TCPRecv( $ConnectedSocket, 2048 )
    

    If @error Then
            GUICtrlSetData($cont1,"Error... Exiting.")
            sleep(500)
            Exit
            EndIf

; Update the edit control with what we got
If $recv ="Packet has arrived." Then GUICtrlSetData($cont1, _
            "Server" & " |-| " & $recv & @CRLF & GUICtrlRead($cont1))
            GUICtrlSetData($cont1,"the dude got the packet!")
            GUICtrlSetData($cont1,"Server"&" > "&$recv&@crlf)
            sleep (1500)
            Exit
WEnd

If $ConnectedSocket <> -1 Then TCPCloseSocket( $ConnectedSocket )

TCPShutDown()

EndFunc
oÝ÷ Ù«­¢+Ø)¼($ÀÌØí¹Q¥µÈôQ¥µÉ%¹¥Ð ¤(ÀÌØí¹¥ôQ¥µÉ¥ ÀÌØí¹Q¥µÈ¤¼ÄÀÀÀ(í%I½Õ¹ ÀÌØí¹¥°È¤ÐìôÅÕ½ÐìÔÅÕ½ÐìQ¡¸(ìµÍ½à À°ÅÕ½ÐíQ¥µÈÅÕ½Ðì°ÅÕ½ÐíÉÑÈÑ¡¸½ÈÅհѼԸ9յȥ̴ÅÕ½ÐìµÀìÀÌØí¹¥¤(ìá¥Ñ1½½À(í¹%(ÀÌØí
½¹¹ÑM½­ÐôQ
AÁÐ ÀÌØí5¥¹M½­Ð¤(ͱÀ ØÀÀÀ¤í¥Ñ̽ÙÈÔ¹ÍÑ¥±°Ý½¹ÐÉ¥ÍÑÈ)U¹Ñ¥°ÀÌØí
½¹¹ÑM½­Ð±ÐìÐì´Ä½ÈI½Õ¹ ÀÌØí¹¥°È¤ÐìôÅÕ½ÐìÔÅÕ½Ðì)5ͽà À°ÅÕ½ÐíQ¥µÈÅÕ½Ðì°ÅÕ½ÐíÉÑÈÑ¡¸½ÈÅհѼԸ9յȥ̴ÅÕ½ÐìµÀìÀÌØí¹¥¤(

no luck.

Edited by backstabbed

tolle indicium

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...