#include 'WSA_NBTCP.au3' Opt('MustDeclareVars', 1) Opt('TrayAutoPause', 0) ; ;=== IP And Port Settings === Local $sLocalIP = '127.0.0.1' Local $nLocalPort = '61000' ;============================ ; Local $sTitle = 'AutoIt v' & @AutoItVersion & ' - WSA_TCPRecv Benchmark' TraySetToolTip($sTitle) ; If TCPStartup() <> 1 Then MsgBox(8208, $sTitle, 'Error: TCPStartup' & @TAB, 5) Exit EndIf ; Local $nListenSocket = _WSA_TCPListen($sLocalIP, $nLocalPort) Local $err = @error If $err Then MsgBox(8208, $sTitle, $err & ' Error: TCPListen could not bind socket' & @TAB, 5) Exit EndIf ; Local $Accept_Socket, $sRecv, $nError, $Active_Socket = 0, $nActive = 0 Local $nBytes, $nTime, $nTimerDiff, $bdv, $mps, $bytes = 0 Local $timer1, $timer2, $nPackets = 0, $nEmpty = 0 Local $nPlacement = (@DesktopWidth / 2) + 100 ; DllCall('uxtheme.dll', 'none', 'SetThemeAppProperties', 'int', 1) Local $ID_GUI = GUICreate($sTitle, 350, 380, $nPlacement) GUICtrlCreateLabel('Packets Received', 10, 12, 130, 20, 0x0002) Local $ID_IP1 = GUICtrlCreateInput(0, 150, 10, 130, 20, 0x0800) GUICtrlCreateLabel('TCPRecv Speed (ms)', 10, 42, 130, 20, 0x0002) Local $ID_IP2 = GUICtrlCreateInput(0, 150, 40, 130, 20, 0x0800) GUICtrlCreateLabel('TCPAccept Speed (ms)', 10, 72, 130, 20, 0x0002) Local $ID_IP3 = GUICtrlCreateInput(0, 150, 70, 130, 20, 0x0800) GUICtrlCreateLabel('Bytes Received', 10, 102, 130, 20, 0x0002) Local $ID_IP4 = GUICtrlCreateInput(0, 150, 100, 130, 20, 0x0800) GUICtrlCreateLabel('Empty Receives', 10, 132, 130, 20, 0x0002) Local $ID_IP5 = GUICtrlCreateInput(0, 150, 130, 130, 20, 0x0800) GUICtrlCreateLabel('Speed (MB/sec)', 10, 162, 130, 20, 0x0002) Local $ID_IP6 = GUICtrlCreateInput(0, 150, 160, 130, 20, 0x0800) GUICtrlCreateLabel('Session Time (sec)', 10, 192, 130, 20, 0x0002) Local $ID_IP7 = GUICtrlCreateInput(0, 150, 190, 130, 20, 0x0800) GUICtrlCreateLabel('Timeout', 10, 222, 130, 20, 0x0002) Local $ID_PG1 = GUICtrlCreateProgress(150, 220, 130, 20, 0x0800) GUICtrlCreateLabel('Errors', 10, 252, 50, 20, 0x0002) Local $ID_IP8 = GUICtrlCreateEdit(0, 70, 250, 210, 115, 0x0800) GUICtrlSetColor($ID_PG1, 0xFF0000) GUICtrlSetBkColor($ID_PG1, -1) GUISetOnEvent(-3, 'ExitApp') GUISetState(@SW_SHOW, $ID_GUI) OnAutoItExitRegister('ExitApp') Opt('GUIOnEventMode', 1) ; While 1 Do $timer1 = TimerInit() $Accept_Socket = _WSA_TCPAccept($nListenSocket); listen for an active socket GUICtrlSetData($ID_IP3, Round(TimerDiff($timer1), 2)); Display TCPAccept Speed ; If $Accept_Socket > 0 Then $Active_Socket = $Accept_Socket; copy accept socket to active socket GUICtrlSetData($ID_IP5, 0); reset Empty Receives GUICtrlSetData($ID_IP7, 0); reset Session Time GUICtrlSetData($ID_IP8, 0); reset Errors $timer2 = TimerInit() $nActive = 1; set active $nTime = 0 EndIf Until $nActive > 0 ; GUICtrlSetData($ID_IP7, Round(TimerDiff($timer2) / 1000)) ; $timer1 = TimerInit() $sRecv = _WSA_TCPRecv($Active_Socket, 65536, 0, 10); <- 10 seconds $nError = @error $nBytes = @extended GUICtrlSetData($ID_IP2, Round(TimerDiff($timer1), 2)) ; If $nError Then; an error occurred GUICtrlSetData($ID_IP8, 'Disconnected: ' & _WSA_FormatMessage($nError)); display Error ElseIf $nBytes > 0 Then; data received $nPackets += 1 GUICtrlSetData($ID_IP1, $nPackets); do something with received data $bytes += $nBytes GUICtrlSetData($ID_IP4, $bytes & ' (' & Round(($bytes / 1024) / 1000) & ' MB)'); display Total Bytes Received $nActive = 0; reset active ; $nTimerDiff = Round(TimerDiff($timer2) / 1000) If $nTimerDiff > $nTime Then $nTime = $nTimerDiff $bdv = ($bytes / 1024) / 1024 / 1024 $mps = Round($bdv / ($nTime / 1000), 2) GUICtrlSetData($ID_IP6, $mps) EndIf Else $nEmpty += 1 GUICtrlSetData($ID_IP5, $nEmpty); display Empty Receives EndIf ; $nActive += 1 GUICtrlSetData($ID_PG1, Round($nActive / 3.33)); display timeout bar If $nError Then _WSA_TCPCloseSocket($Active_Socket) $Active_Socket = 0; reset $nPackets = 0; reset $nActive = 0; reset $nEmpty = 0; reset $bytes = 0; reset EndIf WEnd ; Func ExitApp() GUIDelete($ID_GUI) If $Active_Socket > 0 Then _WSA_TCPCloseSocket($Active_Socket) EndIf _WSA_TCPCloseSocket($nListenSocket) _WSA_Cleanup() TCPShutdown() Exit EndFunc ;