Jump to content

Server / Client


Recommended Posts

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

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