Sign in to follow this  
Followers 0
FinalVersion

Server / Client

2 posts in this topic

If I send "MsgBox" with the client, it works. But then if I try to send anything a second time, it won't work. Why?

Server

TCPStartup()
$mainSock = TCPListen("127.0.0.1", 1030)
If $mainSock = -1 Then Exit

$sockClient = -1
Do
    $sockClient = TCPAccept($mainSock)
Until $sockClient <> -1

$ret = ""
While 1
    $ret = TCPRecv($sockClient, 1000)
    Switch $ret
        Case "MsgBox"
            MsgBox(0, "", "MsgBox")
            $ret = ""
        Case "Close"
            ExitLoop
            $ret = ""
    EndSwitch
WEnd

TCPCloseSocket($sockClient)
TCPShutdown()

Client

TCPStartup()
$sockMain = TCPConnect("127.0.0.1", 1030)
If $sockMain = -1 Then Exit

$sNode = InputBox("", "")
TCPSend($sockMain, $sNode)

TCPCloseSocket($sockMain)
TCPShutdown()

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Updated Server Code

$IP = "192.168.2.102"

TCPStartup()
$mainSock = TCPListen($IP, 1030)
If $mainSock = -1 Then Exit

$sockClient = -1

$ret = ""
While 1
    If $sockClient = -1 then
        $sockClient = TCPAccept($mainSock)
        _DebugWrite("sockMain = " & $sockClient)
    Else
        $ret = TCPRecv($sockClient, 1000)
        If @error then $sockClient = -1 ;The connection has been closed
        _DebugWrite("Ret = " & $Ret)
        Switch $ret
            Case "MsgBox"
                MsgBox(0, "", "MsgBox")
                $ret = ""
            Case "Close"
                Exitloop
        EndSwitch

    EndIf
WEnd

TCPCloseSocket($mainSock)
TCPShutdown()

Func _DebugWrite($vStr = "")
    ConsoleWrite($vStr & @crlf)
EndFunc
Edited by ChrisL

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  
Followers 0