felanor Posted May 20, 2008 Posted May 20, 2008 Hi Everyone, I have some code that I'm trying to get working. My concept is to have an "update" client on my client machines. When that client runs, it checks in with a server. If that server is currently hosting something, it will download the file and run it. If the server isn't running, the client displays a MsgBox stating that there are no updates currently. My problem occurs when only 2k of my executable are being transferred over. Any help would be greatly appreciated. SERVER $filetosend = FileOpenDialog("File To Send", "C:\", "All (*.*)", 3) $filetoread = FileOpen($filetosend, 16) $datatosend = FileRead($filetoread) FileClose($filetosend) $g_IP = "192.168.2.2" $recv = "" MsgBox(0, "", StringLen($datatosend)) TCPStartup() $MainSocket = TCPListen($g_IP, 12000) If $MainSocket = -1 Then Exit While 1 Do $ConnectedSocket = TCPAccept($MainSocket) Until $ConnectedSocket <> -1 $sent = TCPSend($ConnectedSocket, String($datatosend)) TCPCloseSocket($ConnectedSocket) WEnd and expandcollapse popupCLIENT $IPADDRESS = "[SERVER IP HERE]" $PORT = 12000 $recv = "" TCPStartup() $ConnectedSocket = TCPConnect($IPADDRESS, $PORT) If $ConnectedSocket = -1 Then MsgBox(64, "No Updates", "No Updates Are Available At This Time") Exit EndIf While $recv = "" $recv = TCPRecv($ConnectedSocket, 743048) WEnd MsgBox(0, "Received:", $recv) TCPSend($ConnectedSocket, 1) MsgBox(0, "", StringLen($recv)) If $recv = "" Then MsgBox(64, "No Updates", "No Updates Are Available At This Time") Exit EndIf MsgBox(0, "Update Received", "") MsgBox(0, "Received", $recv) $tempfile = FileOpen(@TempDir&"\update.exe", 18) FileWrite($tempfile, $recv) FileClose($tempfile) MsgBox(0, "Update Written", "") Run(@TempDir&"\update.exe") Exit Check Out My ScriptsFile Property Management - Adjust a file's title, author, subject, etc.
LarryDalooza Posted May 20, 2008 Posted May 20, 2008 String($datatosend)) no no... there may be more no nos ... but this one jumps out. Lar. AutoIt has helped make me wealthy
felanor Posted May 21, 2008 Author Posted May 21, 2008 String($datatosend))no no...there may be more no nos ... but this one jumps out.Lar.Thanks for that!Still not getting the entire file through. Any additional suggestions?~Felanor Check Out My ScriptsFile Property Management - Adjust a file's title, author, subject, etc.
LarryDalooza Posted May 21, 2008 Posted May 21, 2008 TCPSend returns the number of bytes sent... If the return does not match the file length, trim off the number of bytes that were sent and send again... until all bytes are sent. When TCPSending you should really send a "header" before the data... telling the reciever what is coming and how much of it to expect. Lar. AutoIt has helped make me wealthy
felanor Posted May 21, 2008 Author Posted May 21, 2008 TCPSend returns the number of bytes sent... If the return does not match the file length, trim off the number of bytes that were sent and send again... until all bytes are sent.When TCPSending you should really send a "header" before the data... telling the reciever what is coming and how much of it to expect.Lar.The listening value for maximum characters with the TCPRecv command is larger than the data I'm sending, which is why I'm being thrown for a loop.Thanks,~Felanor Check Out My ScriptsFile Property Management - Adjust a file's title, author, subject, etc.
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