|
本帖最后由 bingxing8000 于 2011-2-11 16:37 编辑
小弟现在刚开始接触autoit里的tcp ,现在需要把一台主机的磁盘的使用情况显示到另一台主机
一下是小弟的代码,望指教
服务器端
#include <GUIConstantsEx.au3>
$form=GUICreate("磁盘使用量",300,200)
GUISetState(@SW_SHOW)
_SkinGUI("C:\Program Files\SkinCrafterDll.dll", "C:\Program Files\vista_style.skf", $form)
$c=DriveSpaceFree( "c:\" )/DriveSpaceTotal( "c:\" )*100 & "%" ;C盘剩余空间占用的百分比
$d=DriveSpaceFree( "d:\" )/DriveSpaceTotal( "d:\" )*100 & "%" ;d盘剩余空间占用的百分比
$e=DriveSpaceFree( "e:\" )/DriveSpaceTotal( "e:\" ) *100 & "%" ;e盘剩余空间占用的百分比
GUICtrlCreateLabel ("C盘剩余空间",10,30,100,50)
$box1=GUICtrlCreateLabel ("",120,30,120,50)
GUICtrlSetData ($box1,$c)
GUICtrlCreateLabel ("D盘剩余空间",10,80,100,50)
$box3=GUICtrlCreateLabel ("",120,80,120,50)
GUICtrlSetData ($box3,$d)
GUICtrlCreateLabel ("E盘剩余空间",10,130,100,50)
$box5=GUICtrlCreateLabel ("",120,130,120,50)
GUICtrlSetData ($box5,$e)
TCPStartup() ;开始 TCP/UDP 服务
$lianjie=TCPListen(@IPAddress1,44556) ;创建一个套接字(socket)监听.
If $lianjie= -1 Then MsgBox(0,"警告","服务器开启失败") ; 创建监听不成功就退出
TCPAccept($lianjie) ;尝试接受一个套接字(socket)连接.
$box6= StringToBinary($c, 4);转换字符串为二进制数据. 标志 = 4, 二进制数据为 UTF8 编码
TCPSend($lianjie,$box6) ;在已经连接的套接字(socket)上面发送数据.
While 1
$msg=GUIGetMsg()
Select
Case $msg= -3
_ent()
EndSelect
WEnd
Func _ent()
TCPCloseSocket($lianjie) ;关闭一个 TCP 套接字(socket).
TCPShutdown () ;停止 TCP/UDP 服务
Exit
EndFunc
Func _SkinGUI($SkincrafterDll, $SkincrafterSkin, $Handle)
$Dll = DllOpen($SkincrafterDll)
DllCall($Dll, "int:cdecl", "InitLicenKeys", "wstr", "1", "wstr", "", "wstr", "1@1.com", "wstr", "1")
DllCall($Dll, "int:cdecl", "InitDecoration", "int", 1)
DllCall($Dll, "int:cdecl", "LoadSkinFromFile", "wstr", $SkincrafterSkin)
DllCall($Dll, "int:cdecl", "DecorateAs", "int", $Handle, "int", 25)
DllCall($Dll, "int:cdecl", "ApplySkin")
EndFunc ;==>_SkinGUI
客户端
#include <GUIConstantsEx.au3>
$form=GUICreate("磁盘使用量",300,200)
GUISetState(@SW_SHOW)
_SkinGUI("C:\Program Files\SkinCrafterDll.dll", "C:\Program Files\vista_style.skf", $form)
$box3="10.0.90.214"
TCPStartup() ;开始 TCP/UDP 服务
$lianjie=TCPConnect($box3,44556) ;创建一个套接字(socket)连接到已经存在的服务器..
If $lianjie= -1 Then MsgBox(0,"提醒",$box3 & " 服务器未开启") ; 创建监听不成功就退出
$box5=TCPRecv($lianjie,2048) ;从已经连接的套接字里面接收数据
$box5=BinaryToString($box5, 4);转换一个二进制变量为一个字符串. 标志 = 4, 二进制 数据原先为 UTF8 编码
While 1
$msg=GUIGetMsg()
Select
Case $msg= -3
_ent()
Case $msg=$box4
MsgBox(0,"警告",$box5)
EndSelect
WEnd
Func _ent()
TCPCloseSocket($lianjie) ;关闭一个 TCP 套接字(socket).
TCPShutdown () ;停止 TCP/UDP 服务
Exit
EndFunc
Func _SkinGUI($SkincrafterDll, $SkincrafterSkin, $Handle)
$Dll = DllOpen($SkincrafterDll)
DllCall($Dll, "int:cdecl", "InitLicenKeys", "wstr", "1", "wstr", "", "wstr", "1@1.com", "wstr", "1")
DllCall($Dll, "int:cdecl", "InitDecoration", "int", 1)
DllCall($Dll, "int:cdecl", "LoadSkinFromFile", "wstr", $SkincrafterSkin)
DllCall($Dll, "int:cdecl", "DecorateAs", "int", $Handle, "int", 25)
DllCall($Dll, "int:cdecl", "ApplySkin")
EndFunc ;==>_SkinGUI |
|