Sample code for 30+ languages & platforms
AutoIt

Accept Connection on Socket

See more Socket/SSL/TLS Examples

Demonstrates how to create a TCP/IP socket, listen on a port, accept an incoming connection, and send a "Hello World" message to the client.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

$oListenSocket = ObjCreate("Chilkat.Socket")

; Bind to a port and listen for incoming connections:
; This example will listen at port 5555 and allows for a backlog
; of 25 pending connection requests.
$bSuccess = $oListenSocket.BindAndListen(5555,25)
If ($bSuccess = False) Then
    ConsoleWrite($oListenSocket.LastErrorText & @CRLF)
    Exit
EndIf

; Get the next incoming connection
; Wait a maximum of 20 seconds (20000 millisec)
$oConnectedSocket = ObjCreate("Chilkat.Socket")
$bSuccess = $oListenSocket.AcceptNext(20000,$oConnectedSocket)
If ($bSuccess = False) Then
    ConsoleWrite($oListenSocket.LastErrorText & @CRLF)
    Exit
EndIf

; Set maximum timeouts for reading an writing (in millisec)
$oConnectedSocket.MaxReadIdleMs = 10000
$oConnectedSocket.MaxSendIdleMs = 10000

; Send a "Hello World!" message to the client:
$bSuccess = $oConnectedSocket.SendString("Hello World!")
If ($bSuccess <> True) Then
    ConsoleWrite($oConnectedSocket.LastErrorText & @CRLF)
    Exit
EndIf

; Close the connection with the client.
; Wait a max of 20 seconds (20000 millsec)
$bSuccess = $oConnectedSocket.Close(20000)

ConsoleWrite("success!" & @CRLF)