Jump to content

TCP - Client hangs up


Recommended Posts

My host script sends the string "~~accepted" to the client script if the user presses "yes" to accept the client's connection to the host. If the user presses "no" to deny the connection from the client to the host, the host will send the string "~~rejected" to the client. If the client detects that the host accepted the connection it will continue with normal operations, but if it detected the host rejected the connection it will exit. The problem is that the client is getting stuck in one of the while loops. Here is the code I have:

Part of client script

; Wait For Connection
;==============================================
$connection = -1
While $connection = -1
  Sleep(10)
  $connection = TCPAccept($socket)
Wend
$recv = ""
While $recv <> "~~accepted"
  Sleep(10)
  $recv = TCPRecv($socket, $n_maxrecv)
  If $recv = "~~rejected" Then
    GUICtrlSetData($edit, "~~Connection Rejected" & @CRLF, 1)
    WinSetTitle($GOOEY,"","Connection Rejected")
    Sleep(2000)
    $failed = 1
    Exit
  EndIf
Wend
GUICtrlSetData($edit, "~~Connection Accepted" & @CRLF, 1)
WinSetTitle($GOOEY,"","Client - Host Connected")

I hope that someone will be able to help me! :)

Link to comment
Share on other sites

See this post for tcp client/server sample programs.

TCP Echo Server

Roy  :)

<{POST_SNAPBACK}>

I saw that a while back. Good scripting, but bad for someone (like me) that can't figure out how to even fix a small part of a script. Thanks for the help though, it was very appreciated!

This code should work though but it doesn't. Any help?

Link to comment
Share on other sites

Well I haven't used those TCP functions in the beta, but I suspect if the socket is broken, TCPRecv() is going to return 0 or "" or something else besides "~~rejected" I'd add a case to check for that.

Link to comment
Share on other sites

Well I haven't used those TCP functions in the beta, but I suspect if the socket is broken, TCPRecv() is going to return 0 or "" or something else besides "~~rejected"  I'd add a case to check for that.

<{POST_SNAPBACK}>

Exactly why I have

While $recv <> "~~accepted"

because "" <> "~~accepted" and 0 <> "~accepted". Also, the script exits if TCPConnect fails (returns -1), which is basically saying, "if the socket is broken then exit". Another thing with the "~~rejected" string: The host sends that string to the client based on if the host accepted or rejected the clients connection. It is not returned by TCPRecv() if it fails.

TCPRecv:

Return Value

Success: Returns string send by the connected socket.

Failure: Returns "" and set @error according to Windows API WSAGetError return.

It returns a blank string "" if it fails. A blank string is not equal to "~~accepted" or "~~rejected" so it will keep on looping until it gets one of those strings from the host. My problem is that it keeps on looping no matter what.

Thanks for the replys.

Link to comment
Share on other sites

The ToolTip didn't display at all so that must mean that it is hanging up in the first loop. I know the syntax is right for the first loop as TCPAccept returns -1 if there is no connection. That might mean there is a problem with the host script.

Here are my two scripts:

Copy_of_TCPchat_host.au3

Copy_of_TCPchat_client.au3

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