Jump to content

Know if a socket is opened.


Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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