本帖最后由 jycel 于 2009-10-27 14:46 编辑
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=b.ico
#AutoIt3Wrapper_outfile=SendaFile.exe
#AutoIt3Wrapper_Res_Comment=文件传送-发送端
#AutoIt3Wrapper_Res_Description=文件传送程序
#AutoIt3Wrapper_Res_LegalCopyright=BY-Jycel
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#NoTrayIcon
$fileini = @ScriptDir & "\File.ini"
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\桌面\sendfile.kxf
$Form1 = GUICreate("请稍候,正在发送中……", 391, 122, 266, 477)
$Group1 = GUICtrlCreateGroup("", 3, 0, 385, 113)
$Label1 = GUICtrlCreateLabel("文件大小:", 11, 16, 364, 17)
GUICtrlSetColor(-1, 0x0000FF)
$Labeljd = GUICtrlCreateLabel("已经发送:", 11, 40, 364, 17)
GUICtrlSetColor(-1, 0x0000FF)
$Label2 = GUICtrlCreateLabel("", 355, 88, 30, 17)
GUICtrlSetColor(-1, 0x0000FF)
$Label3 = GUICtrlCreateLabel("发送状态:", 11, 64, 364, 17)
GUICtrlSetColor(-1, 0x0000FF)
$Label4 = GUICtrlCreateProgress(11, 88, 337, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_SendFile()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _SendFile()
;~ Local $g_IP = IniRead($fileini, "配置信息", "接收地址", "")
Local $g_IP = IniRead($fileini, "配置信息", "接收地址", "");@IPAddress1
;Local $sendfile = @ScriptDir & "\test.rar"
;~ Local $sendfile = IniRead($fileini, "配置信息", "发送文件", "")
Local $sendfile = IniRead($fileini, "配置信息", "发送文件", "");@ScriptDir & '\ini.txt'
Dim $var = 1
;开始tcp服务
TCPStartup()
;创建一个套接字(socket)连接到已经存在的服务器
$socket = TCPConnect($g_IP, 62345)
If $socket = -1 Then
MsgBox(0, "出错", "连接到服务器出错: " & @error)
Exit
EndIf
$DnSize = FileGetSize($sendfile)
$file = FileOpen($sendfile, 16)
;打开读取文件
While 1
$fdata = FileRead($file, 1024 * 1000)
If @error = -1 Then ExitLoop
TCPSend($socket, $fdata)
$var += 1
;TrayTip("msg", $var, 5)
GUICtrlSetData($Label1, "文件大小:" & $DnSize&"字节")
GUICtrlSetData($Label3, "发送状态:正在发送中……")
$DnPercent = Int($var * 1024 * 1000 / $DnSize * 100)
GUICtrlSetData($Label2, GUICtrlRead($Label4)&"%")
$jd=GUICtrlRead($Label4)/100
GUICtrlSetData($Labeljd,"已经发送:"&$jd*$DnSize&"字节")
GUICtrlSetData($Label4, $DnPercent)
WEnd
TCPCloseSocket($socket)
TCPShutdown()
GUICtrlSetData($Label3, "发送状态:发送完毕!3秒后退出")
Sleep(1000)
GUICtrlSetData($Label3, "发送状态:发送完毕!2秒后退出")
Sleep(1000)
GUICtrlSetData($Label3, "发送状态:发送完毕!1秒后退出")
Sleep(1000)
Exit
EndFunc ;==>_SendFile
|