|
发表于 2013-4-4 23:37:53
|
显示全部楼层
_recvFiles()
Func _recvFiles();接收文件
Local $g_IP = @IPAddress1
Local $downfile = @ScriptDir & "\test3.rar"
; 开始 TCP 服务
TCPStartup()
; 创建监听套接字(SOCKET)
$MainSocket = TCPListen($g_IP, 65432, 100)
If $MainSocket = -1 Then Exit
$file = FileOpen($downfile, 2 + 8 + 16)
If $file = -1 Then
MsgBox(0, "错误", "无法打开目标文件。")
Exit
EndIf
; 查看客户端连接
;--------------------
Dim $var = 1
While 1
$ConnectedSocket = TCPAccept($MainSocket)
If $ConnectedSocket >= 0 Then
;MsgBox(0, "", "我的服务器 - 客户端已经连接")
;打开文件准备接收
;开始接收文件
While 1
$sBuff = TCPRecv($ConnectedSocket, 1024 * 1000)
If @error Then
FileClose($downfile)
Return $downfile
EndIf
;写文件
FileWrite($downfile, $sBuff)
$var += 1
TrayTip("msg", $var, 5)
WEnd
EndIf
WEnd
;关闭套接字,停止TCP服务
TCPCloseSocket($ConnectedSocket)
TCPShutdown()
EndFunc ;==>_recvFiles |
|