Alexxander

TCP reconnect ?

5 posts in this topic

hi

i have this code

TCPStartup()
$TCPL = TCPListen(@IPAddress1, 1234)

Do
    $TCPA = TCPAccept($TCPL)
Until $TCPA <> -1

While 1
    $TCPR = TCPRecv($TCPA, 9999999)
    If $TCPR <> "" Then
        ConsoleWrite($TCPR)
    EndIf
WEnd

it is working great , but when the client disconnected then reconnect to my server (autoit) i will not receive the string anymore

how could i make my autoit server code always receive data even if the clinet reconnected ?

or maybe detect that client is disconnected and automatically reestablish the connection , any ideas ?


Share this post


Link to post
Share on other sites



Hi,

check out the attached file, it's a multiclient-server by Ken Piper. I found it somewhere on the forum some time ago but can't find the thread anymore.

It can accept multiple clients, recieve data from then and also checks for disconnected ones.

Loads of comments in there, really simple.

tcp_server.au3

Share this post


Link to post
Share on other sites

Hi,

check out the attached file, it's a multiclient-server by Ken Piper. I found it somewhere on the forum some time ago but can't find the thread anymore.

It can accept multiple clients, recieve data from then and also checks for disconnected ones.

Loads of comments in there, really simple.

 

i had edited the code header to this

#region ;Safe-to-edit things are below
Global $BindIP = @IPAddress1    ;Listen on all addresses
Global $BindPort = 1234        ;Listen on port 8080
Global $Timeout = 15000        ;Max idle time is 15 seconds before calling a connection "dead"
Global $PacketSize = 2048    ;Max packet size per-check is 2KB
Global $MaxClients = 50        ;Max simultaneous clients is 50
#endregion ;Stuff you shouldn't touch is below

i cant revive any data and the client say when sending the second packed that pipe is broken ..


Share this post


Link to post
Share on other sites

 

pipe is broken

 

Never heard, is that a custom error message from your client?

Can you post your client script?

Share this post


Link to post
Share on other sites

TCPStartup()

$ConnectedSocket = -1

$MainSocket = TCPListen("0.0.0.0", 5555)
If $MainSocket = -1 Then
    MsgBox(16, "Error", "Can not open TCP Socket")
    Exit
EndIf

Waitconn()

While 1
    $text = TCPRecv($ConnectedSocket, 2048)
    $ierror = @error
    If Not $ierror Then
        ConsoleWrite($text & @CRLF)
    ElseIf $ierror = 10054 Then
        Waitconn()
    Else
        ;ConsoleWrite($ierror & @CRLF)
    EndIf
WEnd


Func Waitconn()
    ConsoleWrite("waiting for connection" & @CRLF)
    Do
        $ConnectedSocket = TCPAccept($MainSocket)
    Until $ConnectedSocket <> -1
    ConsoleWrite("connected" & @CRLF)
EndFunc   ;==>Waitconn

this works for me

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