#Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_Icon=..\Aut2Exe\Icons\zz.ico
#PRE_Res_requestedExecutionLevel=None
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#Include <GuiListBox.au3>
#Include <Timers.au3>
#Include <date.au3>
#Include <Array.au3>
Opt("TrayAutoPause",0)
Opt("GUIOnEventMode", 1)
Global $Form1,$Label1,$Label2,$List,$Button1,$MainSocket, $ConnectedSocket,$SocketSend,$sRecv,$sendflag
$PortReceive="64213"
$PortSend="65213"
#Region ### START Koda GUI section ### Form=
$sSrvIP=IniRead("TimeServer.ini","TimeServer","ServerIP","192.0.0.3")
$Form1 = GUICreate("TimeServer("&$sSrvIP&")", 400,220, @DesktopWidth-415, @DesktopHeight-290)
$List = GUICtrlCreateList("", 3, 5, 260, 210)
$Label1 = GUICtrlCreateLabel("", 265, 10, 200, 40)
GUICtrlSetFont(-1, 8, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
$Label2 = GUICtrlCreateLabel("", 265, 35, 200, 30)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x800080)
$Label3 = GUICtrlCreateLabel("", 265, 60, 100, 30)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Button1 = GUICtrlCreateButton("Clear Log", 275, 140, 113, 65)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
GUICtrlSetData($List,"This is a test!!"&@CRLF)
GUISetOnEvent($GUI_EVENT_CLOSE, "main")
GUISetOnEvent($Button1, "main")
If Not FileExists("SaveTime.exe") Then
FileInstall("SaveTime.exe",@ScriptDir&"\SaveTime.exe",1)
EndIf
GUICtrlSetData($Label3,"IP="&$sSrvIP)
UDPStartup()
$MainSocket = UDPBind($sSrvIP,$PortReceive)
If @error<>0 Then
MsgBox(0,"Error!","Can't Blind the port:"&$PortReceive)
EndIf
#EndRegion ### END Koda GUI section ###
While 1
$sRecv = UDPRecv($MainSocket,2048,1)
If $sRecv<>"" Then
$sRecv = BinaryToString($sRecv, 4)
;MsgBox(0,"Server",$sRecv&" "&$PortSend)
$sendflag=0
$start=TimerInit()
Do
$SocketSend = UDPOpen($sRecv,$PortSend)
If Not @error Then
$sendflag=1
EndIf
If TimerDiff($start)/1000>2 Then
ExitLoop
EndIf
Until $sendflag
If $sendflag Then
$time=@MON&"-"&@MDAY&"-"&@YEAR&"-"&@HOUR&"-"&@MIN&"-"&@SEC
UDPSend($SocketSend,$time)
UDPCloseSocket($SocketSend)
GUICtrlSetData($List, _Now()&"->Clint:"&$sRecv&@CRLF)
EndIf
EndIf
WEnd
Func main()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
UDPCloseSocket($MainSocket)
UDPCloseSocket($SocketSend)
UDPShutdown()
Exit
Case $Button1
GUICtrlSetData($List,"")
EndSwitch
EndFunc