1 | #include <MsgBoxConstants.au3> |
---|
2 | |
---|
3 | Example() |
---|
4 | |
---|
5 | Func Example() |
---|
6 | TCPStartup() |
---|
7 | |
---|
8 | OnAutoItExitRegister("OnAutoItExit") |
---|
9 | |
---|
10 | Local $sIPAddress = "127.0.0.1" |
---|
11 | Local $iPort = 65432 |
---|
12 | |
---|
13 | Local $iSocket = TCPConnect($sIPAddress, $iPort) |
---|
14 | Local $iError = 0 |
---|
15 | |
---|
16 | If @error Then |
---|
17 | $iError = @error |
---|
18 | MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Could not connect, Error code: " & $iError) |
---|
19 | Return False |
---|
20 | EndIf |
---|
21 | |
---|
22 | Local $sData = "" |
---|
23 | |
---|
24 | Do |
---|
25 | $sData = TCPRecv($iSocket, 7) |
---|
26 | |
---|
27 | If @error Then |
---|
28 | $iError = @error |
---|
29 | |
---|
30 | Local $aRet = DllCall("Ws2_32.dll", "int", "WSAGetLastError") |
---|
31 | |
---|
32 | MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Connection lost, Error code: " & $iError & _ |
---|
33 | @CRLF & "WSAError: " & $aRet[0]) |
---|
34 | Return False |
---|
35 | EndIf |
---|
36 | Until $sData = "{READY}" |
---|
37 | |
---|
38 | MsgBox($MB_SYSTEMMODAL, "", "Client:" & @CRLF & "Success.") |
---|
39 | |
---|
40 | TCPCloseSocket($iSocket) |
---|
41 | EndFunc ;==>Example |
---|
42 | |
---|
43 | Func OnAutoItExit() |
---|
44 | TCPShutdown() |
---|
45 | EndFunc ;==>OnAutoItExit |
---|