1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** |
---|
2 | #AutoIt3Wrapper_Res_Language=1031 |
---|
3 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y |
---|
4 | #AutoIt3Wrapper_Run_Stop_OnError=y |
---|
5 | #AutoIt3Wrapper_Run_Tidy=y |
---|
6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** |
---|
7 | |
---|
8 | ; I am the server, start me first! (Start in second the TCPConnect example script). |
---|
9 | |
---|
10 | #include <MsgBoxConstants.au3> |
---|
11 | |
---|
12 | Global $iSocket |
---|
13 | |
---|
14 | Example() |
---|
15 | |
---|
16 | Func Example() |
---|
17 | TCPStartup() |
---|
18 | |
---|
19 | OnAutoItExitRegister("OnAutoItExit") |
---|
20 | |
---|
21 | Local $sIPAddress = "127.0.0.1" |
---|
22 | Local $iPort = 65432 |
---|
23 | Local $iListenSocket = TCPListen($sIPAddress, $iPort, 100) |
---|
24 | Local $iError = 0 |
---|
25 | |
---|
26 | If @error Then |
---|
27 | $iError = @error |
---|
28 | MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "SERVER:", "Could not listen, Error code: " & $iError) |
---|
29 | Return False |
---|
30 | EndIf |
---|
31 | |
---|
32 | Local $iSocket = 0 |
---|
33 | Do |
---|
34 | $iSocket = TCPAccept($iListenSocket) |
---|
35 | |
---|
36 | If @error Then |
---|
37 | $iError = @error |
---|
38 | MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "SERVER:", "Could not accept the incoming connection, Error code: " & $iError) |
---|
39 | Return False |
---|
40 | EndIf |
---|
41 | |
---|
42 | $recv = TCPRecv($iSocket, 4) |
---|
43 | If $recv Then |
---|
44 | MsgBox(0, "SERVER:", "Receive: " & $recv & @CRLF & "After pressing ok, will send TCPS...") |
---|
45 | $send = TCPSend($iSocket, "TCPS") |
---|
46 | EndIf |
---|
47 | |
---|
48 | Until $iSocket <> -1 ;if different from -1 a client is connected. |
---|
49 | |
---|
50 | EndFunc ;==>Example |
---|
51 | |
---|
52 | Func OnAutoItExit() |
---|
53 | TCPCloseSocket($iSocket) |
---|
54 | TCPShutdown() |
---|
55 | EndFunc ;==>OnAutoItExit |
---|