CODICE
Func _TCPFileSend($sFile,$_socket,$progress_bar=False,$title="",$main="")
Local $error=False, $num=1, $wait=5000, $ack=False
$sFileOpen=FileOpen($sFile, 16 + 0)
$sFileRead=FileRead($sFileOpen)
FileClose($sFileOpen)
$sFileSize=BinaryLen($sFileRead)
$init=TimerInit()
TCPSend($_socket,"xBufferOnx"& $sFileSize)
While TimerDiff($init) < $wait
$recv=TCPRecv($_socket,2048)
If StringInStr($recv,"xContinuex",1) Then
$init=TimerInit()
$ack=True
ExitLoop
EndIf
WEnd
If $ack=True Then
If $sFileSize < 100000 Then
$TCPSend=TCPSend($_socket,$sFileRead)
$progress_bar=False
Else
If $progress_bar=True Then ProgressOn($title,$main,"0%",-1,-1,16)
$buff=$sFileRead
Do
If $progress_bar=True Then
$perc=Round((BinaryLen($buff)/$sFileSize)*100,0)
$percfin=100-$perc
ProgressSet($percfin,$percfin &"%")
EndIf
$TCPSend=TCPSend($_socket,BinaryMid($buff,1,100000))
While 1
$recv=TCPRecv($_socket,2048)
If StringInStr($recv,"XStreamX",1) Then ExitLoop
WEnd
$buff=BinaryMid($buff,$TCPSend+1)
Until BinaryLen($buff)=0
EndIf
Sleep(100)
For $i=1 To 5
TCPSend($_socket,"xEndTransx")
Next
If $progress_bar=True Then
If $progress_bar=True Then ProgressOff()
EndIf
Else
$error=True
EndIf
If $error=True Then
Return 0
Else
Return 1
EndIf
EndFunc ;==> _TCPFileSend
Func _TCPFileRecv($rFile,$_socket,$progress_bar=False,$title="",$main="")
Local $error=False
Local $buff, $no_recv_count=0, $wait=5000, $syn=False
$init=TimerInit()
While TimerDiff($init) < $wait
$recv=TCPRecv($_socket,2024)
If StringInStr($recv,"xBufferOnx",1) Then
$init=TimerInit()
$syn=True
TCPSend($_socket,"xContinuex")
ExitLoop
EndIf
WEnd
If $syn=True Then
If $progress_bar=True Then ProgressOn($title,$main,"0%",-1,-1,16)
$size=StringReplace($recv,"xBufferOnx","")
$binary_recv=0
While 1
$TCPRecv=TCPRecv($_socket,100000)
If StringLen($TCPRecv) Then
If StringInStr($TCPRecv,"xEndTransx",1) Then
If $progress_bar=True Then ProgressOff()
ExitLoop
EndIf
If $TCPRecv <> "" Then
If $TCPRecv=="xEndTransx" Then ExitLoop
If $progress_bar=True Then
$binary_recv+=BinaryLen($TCPRecv)
$perc=Round(($binary_recv/$size)*100,0)
ProgressSet($perc,$perc &"%")
EndIf
$str=BinaryToString($TCPRecv)
$buff &=$str
$no_recv_count=0
TCPSend($_socket,"XStreamX")
EndIf
EndIf
WEnd
If $buff="" Then
$error=True
Else
$buff=StringToBinary($buff)
$rFileOpen=FileOpen($rFile,16+2)
If $rFileOpen=-1 Then
$error=True
Else
$rFileWrite=FileWrite($rFileOpen,$buff)
If $rFileWrite=0 Then
$error=True
EndIf
FileClose($rFileOpen)
EndIf
EndIf
Else
$error=True
EndIf
If $error=True Then
Return 0
Else
Return 1
EndIf
EndFunc ;==> _TCPFileRecv