TCPFileTransfer

« Older   Newer »
  Share  
xdmisterx
CAT_IMG Posted on 12/12/2009, 13:45     +1   -1




Funzione per il trasferimento di file con progressbar:

SPOILER (click to view)
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


edit: aggiornata la funzione perchè aveva problemi di sincronizzazione.

ciao :)

Edited by xdmisterx - 8/1/2010, 17:22
 
Top
nicofossa96
CAT_IMG Posted on 24/12/2009, 15:46     +1   -1




Mi ha aiutato a trasferire i file dal pc del mio amico al mio, Grazie!
 
Top
°-_ LoL _-°
CAT_IMG Posted on 4/2/2010, 15:06     +1   -1




A me non va. Sei sicuro che funzioni?
 
Top
xdmisterx
CAT_IMG Posted on 4/2/2010, 15:09     +1   -1




sinceramente l'ho usata tantissime volte e funziona, dipende come la usi. magari posta il sorgente e vediamo dovè il problema.
 
Top
ienag3™
CAT_IMG Posted on 1/8/2011, 23:41     +1   -1




funziona solo in LAN ?
 
Top
Cale92
CAT_IMG Posted on 2/8/2011, 05:44     +1   -1




se inserisci i dati corretti funziona anche in internet
 
Top
ienag3™
CAT_IMG Posted on 2/8/2011, 14:40     +1   -1




mi spiegheresti come fare ?
sto provando a fare un tipo di torrent ma non riesco a capire come mettere in ascolto
sul mio IP internet...

con tcp nn mi invia nnt , invecie con udp mi invia ma nn mi ascolta..

mi potresti fare un esempio ? ;)
 
Top
LoGiX
CAT_IMG Posted on 2/8/2011, 15:03     +1   -1




ienag3: ti sei presentato? :S
Comunque in locale devi mettere i parametri giusti, e in remoto hai le porte aperte? Li ha quello a cui invii i file?
 
Top
ienag3™
CAT_IMG Posted on 2/8/2011, 15:08     +1   -1




credo di si mi sono iscritto parecchio tempo fa...

cmq ho provato a fare un giro delle porte ma nulla, nn si connette

TCPStartup()

for $i=1 to 65000
$ConnectedSocket = TCPListen("151.42.228.169",$i,100)

If not @error Then
MsgBox(4112, "A", "FUNZIA")
EndIf
next


se provo ad scoltare il mio ip pubblico dovrebbe andare no ?
 
Top
LoGiX
CAT_IMG Posted on 2/8/2011, 16:53     +1   -1




Certo...che no.
Non puoi connetterti a te stesso, al massimo il tuo ip locale..
che puoi trovare con la macro: @IpAddress1..
 
Top
»Master
CAT_IMG Posted on 2/8/2011, 23:32     +1   -1




a quanto pare devi leggerti il minimo sulle connessioni, su come funzionano e poi provare a effettuare una ;) e le connessioni TCP e UDP funzionano quasi nello stesso modo.
 
Top
ienag3™
CAT_IMG Posted on 2/8/2011, 23:55     +1   -1




si ho provato e mi funzia da ip pubblico e ascoltando il mio locale va...
cmq adesso sono riuscito in parte togliendo sicurezze nelle router, ma volevo sapere se è possibile svincolarsi dalle porte visto ke adesso io ricevo e mando bn, ma il mio amico manda a me ma non riceve -.-

p.s: sono in quinta ho gia studiato questi protocolli ;) e in sistemi con java nn c'erano sti poblemi
 
Top
I.Ren
CAT_IMG Posted on 3/8/2011, 08:14     +1   -1




una domandina, u poco ot:

se sai usare il java, se la non avevi problemi, perchè mai usi autoit che è:

- estremamente limitato (niente multithreading o liste)
- only windows
 
Top
ienag3™
CAT_IMG Posted on 3/8/2011, 10:43     +1   -1




perke java rikiede circa il 200% di tempo in piu e questo progetto non lo si puo fare in java... cmq ho solo kiesto un esempio e delle spiegazioni magari ma se la risposta è vai a leggere su wikip. grazie lostesso ;)
una persona fa una domanda e la trattate come una merda bha! :huh:
 
Top
Cale92
CAT_IMG Posted on 3/8/2011, 11:51     +1   -1




non é trattare di merda però se ti leggi velocemente l'help di scite trovi tutte le risposte con anche degli esempi. é facile sono si e no 5 comandi in tutto
 
Top
23 replies since 12/12/2009, 13:45   654 views
  Share