Jump to content
Sign in to follow this  
79137913

Know if a socket is opened.

Recommended Posts

79137913

HELLO!!!
 
Well...
 
I have this conection code:
 

Func _Conectar(ByRef $sock, $sIP, $sPORT) ;Conecta un socket a un Ip y un Puerto.
    While TCPStartup() = 0
        Sleep(10)
    WEnd
    While True
        $sock = TCPConnect($sIP, $sPORT)
        If $sock > 0 Then
            ExitLoop
        EndIf
        Sleep(1000)
    WEnd
EndFunc   ;==>_Conectar

When the socket is conected to the server it will "talk".

How i know if the server has closed the socket (serverside).

I've tried with @Error on TCPRECV but it gives me -1 everytime TCPRECV = ""

Is another way to know this? one without @error, something like IsSocketOpened($socket)

THANKS FOR READING!!!

Share this post


Link to post
Share on other sites
FireFox

Hi,

Welcome to the AutoIt forum :)

Please have a look at the helpfile examples.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
79137913

HELLO!!!

Mr. FireFox...

I already search in help files examplesbut i only found the @error technique.

The TCP Functions are:

Accept

CloseSocket

Connect

IPtoName

Recv

Send

Shutdown

Startup

Timeout

No one of them helps me, because i have Blanks on the "chat" between This Client and the server, but the Connection still opened, i want to try reconect if the connection is closed by any side, no when a nullstring is recived (or nothing is recived).

THANKS FOR READING!!!

Share this post


Link to post
Share on other sites
FireFox

You didn't look how to correctly use those functions.

e.g :

While TCPStartup() = 0
        Sleep(10)
    WEnd

Is a huge no no.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
79137913

HELLO!!!

That Part of the code is to wait until the server is listening.

In others words, it will try to connect until it can make a connection with the server.

Plz tell me whi i'm not using well that function?

My bad...

That part of code is to wait until the TCPStartup is Up and Running.

The other part of the code that you didnt mentioned is to do what i Striked Through.

THANKS FOR READING!!!

Edited by 79137913

Share this post


Link to post
Share on other sites
FireFox

The start up of the TCP/UDP services should not fail (rare exceptions).

Func _Conectar(ByRef $sock, $sIP, $sPORT) ;Conecta un socket a un Ip y un Puerto.
    TCPStartup()
    If @error Then
        $iError = @error
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "TCPStartup(): Error code: " & $iError)
        Return False
    EndIf

    While True
        $sock = TCPConnect($sIP, $sPORT)
        If Not @error Then ExitLoop
        ;else retry connection
        Sleep(1000)
    WEnd
EndFunc   ;==>_Conectar

Concerning the TCPRecv function, if an error is fired it means the connection is lost.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
79137913

HELLO!!!

First of all Thank you.

Now...

Well, i've tried that but it didnt work.

The conecction is ok, but when i:

$Recibe = ""
            While $Recibe = ""
                $Recibe = TCPRecv($Socket,1000)
                $iError = @error
                If $iError Then
                    MsgBox(0,"",$iError)
                EndIf
                Sleep(100)
            WEnd

Every time the server sends information (when this code recieve something diferent of a nullstring) The error is 0 (no error).

But when the server is silent (when this code do not recieve anything (recieve a nullstring)) the error is -1.

I've checked:

And there is no solution, as i see, because every one is getting a -1 when the buffer is empty and when the connection is down... so, we cant differentiate that.

P.S: Plz, answer me :D

THANKS FOR READING!!!

Edited by 79137913

Share this post


Link to post
Share on other sites
FireFox

As I said, -1 means the connection is lost.

It does not mean the server is not sending anything.

You should check the script on server side, there's nothing you can fix here.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
79137913

HELLO!!!

Mr. FireFox, Im sorry for my ignorance...

How the connection could be lost if i can continue sending data to the au3 script after the error arrives :P

In other words:

 

1) I connect to the server

2) I send a "Hello" String

3) The servers answers "Hello"

4) After i recieve the Hello on the Au3 Script and proceced it the next TCPRecv gives me an @error = -1

5) The error continues while nothing is recieved

6) The server sends a Petition for example "GiveMeData"

7) The au3 Script recieve the "GiveMeData" without problems and gives no error on this TCPRecv

8) The au3 Script answers "Im Script Number #"

9) Until i get another string from the server the au3 Script (TCPRecv) keeps giving @error = -1

So, if we use logic... at the 5 point the au3 script socket is down... but how can I recieve data on the 6th point ?

THANKS FOR READING!!!

Edited by 79137913

Share this post


Link to post
Share on other sites
FireFox

Yes you're right, I got this problem once and I did not remember it.

I suggest you to ignore the error.

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
FireFox

And how to check if the connection : send a data (e.g : PING) and wait for its response (e.g : PONG).

You may not have to wait for a response, as the TCP protocol checks for the packet to be successfully sent.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
79137913

HELLO!!!

Great News Im not mad!

BTW i cant Stress the server with a lot of "Pings" every 0.1 seconds form each client.

I will put a directive to reconect every client when it dont recieve instructions in 15 minutes.

Thank you very much!

(the problem isnt solved but i have an answer) :D

THANKS FOR READING!!!

Edited by 79137913

Share this post


Link to post
Share on other sites
FireFox

Of course don't ping it everytime if not needed ;)


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
79137913

HELLO!!!

John ... i've tried that and it didn't work, autoit connect every time i do a tcp Connect.

Thank you, but the timeout option is the best for now.

THANKS FOR READING!!!

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  

×