System Posted March 15, 2009 Share Posted March 15, 2009 Hello, I have got a problem with my "updateprogram" I'm writing on. It should send a .exe-file over TCP. Well it does.. but the file has not the same filesize after Sending (the last time I tried I got the double filesize :-/) and of cause it's not working. sender CODEFunc _updatemode() ;select file Local $File = FileOpenDialog("Bitte wählen sie die Datei aus", @DesktopDir, "client (*.exe)") If @error Then printSystem("update cancelled") return EndIf Local $SplitBits=1024 Local $fileopen = FileOpen($File, 16) Local $open = FileRead($fileopen) ;slize File Local $len=Ceiling(BinaryLen($open)/$SplitBits) Local $data[$len] For $x=0 To $len-1 $data[$x]=BinaryMid ( $open, $x*$SplitBits+1 , $SplitBits ) Next ;sending update command ******************************************* TCPSend($ConnectedSocket,"-update") ;wait for "ok" ********************************************** Local $get="" Do $get = TCPRecv($ConnectedSocket, 2048) Until $get = "ok" ;send package count ********************************************** $get="" printSystem("Sending package count information") Local $len2 = $len If $len2=0 Then $len2="NULL" TCPSend($ConnectedSocket,String($len2)) Do $get = TCPRecv($ConnectedSocket, 2048) Until $get = String($len2) println("") ;send file ********************************************** For $x=0 To $len-1 TCPSend($ConnectedSocket,"ready") printSystem("Package("&$x&"/"&$len-1&") "&round(($x/$len)*100,2)&"%") ;---send bitcount--- Local $BinLen=BinaryLen($data[$x]) If $BinLen=0 Then $BinLen="NULL" TCPSend($ConnectedSocket,String($BinLen)) $get="" Do;answer $get = TCPRecv($ConnectedSocket, 2048) Until $get = String($BinLen) ;---send data--- $get="" TCPSend($ConnectedSocket,$data[$x]) Do;answer $get = TCPRecv($ConnectedSocket, 2048) Until $get = "ok" Next TCPSend($ConnectedSocket,"finished") printSystem("update complete") ;$connectionLost=True EndFunc receiver CODE Case "-update" $bool_cmderror=False TCPSend($ConnectedSocket,"ok") ;getting packagecount Local $len="" Do $len = TCPRecv($ConnectedSocket, 2048) Until $len="NULL" Or Int($len)>0 TCPSend($ConnectedSocket,$len) If $len="Null" Then $len=0 Else $len=int($len) EndIf ;creating data array Local $data[$len] Local $arrayPos=0 ;Getting loop While 1 ;waiting ready Local $get="" Do $get=TCPRecv($ConnectedSocket,2048) Until $get="ready" Or $get="finished" If $get="finished" Then ExitLoop ;getting bitcount Local $bitcount="" Do $bitcount = TCPRecv($ConnectedSocket, 2048) Until $bitcount="NULL" Or Int($bitcount)>0 TCPSend($ConnectedSocket,$bitcount) If $bitcount="Null" Then $bitcount=0 Else $bitcount=int($bitcount) EndIf ;getting data Do $data[$arrayPos] = TCPRecv($ConnectedSocket, $bitcount) Until BinaryLen($data[$arrayPos])=$bitcount $arrayPos+=1 TCPSend($ConnectedSocket,"ok") WEnd $outp=Binary("") For $i=0 To $len-1 $outp&=$data[$i] Next $open = FileOpen("clientUpdate.exe",2) FileWrite($open,$outp) FileClose($open) ;TCPSend($ConnectedSocket,"receaved file") EndSwitch Thanks for your help in advance Systemdir Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now