Clock Posted June 6, 2011 Share Posted June 6, 2011 (edited) Hello everyone,This is my first post in the autoit forum. Usually i don't sign up on boards, because I'm not very active in writing posts and i would feel bad if i only post here if i have a question.After reading the board for a while and learning about AutoIT i decided to sign up anyway, because i made AutoIT to some kind of hobby of mine, as it lets me program creative applications without knowing very much about complex programming. I hope that atleast for everything i ask, i can help out someone else on this forum.Now to my problem:I've been experimenting with File Transfer via TCP and even though there are many UDFs out there, i couldn't get it to work properply.At the moment, im not even sure which of my approaches with the different UDFs was the right one, so I'm posting my last try:SENDER$test = FileOpen("D:\test.zip", 16) $bin = FileRead($test) ;MsgBox("","",$bin) Local $S_ip = "<onlineip>" Local $S_Port = 21525 TCPStartup() Local $socket = TCPConnect($S_ip, $S_Port) If $socket <> -1 Then TCPSend($socket, $bin) TCPCloseSocket($socket) EndIf TCPShutdown()RECEIVERit uses the _TCPFileTransfer.au3 , by DELmEUnluckily he hasn't been around for a long time now, so i decided to post a new thread. I don't necessarily want to use that UDF, I'm grateful for every help to make it work and to understand it and I don't understand his functions very well.#include <_TCPFileTransfer.au3> TCPStartup() $sock = TCPListen("<onlineip>",21525) Do $ssock = TCPAccept($sock) Until $ssock <> -1 $rFileRecv = _TCPFileRecv($ssock, "test.zip") MsgBox(0,"Server",$rFileRecv) TCPShutdown()NOTE: change <onlineip> to the ip of the server, before trying outWhat happens when running?When i start the receiver and then start the sender, the file gets transfered, but the scripts stops and the MsgBox doesnt show up.If i try to open the archive, it tells me that another process is acessing the file and i can not open it. After forcing the Server to quit, i can open the archive and the data seems to be okay.At first i thought that maybe the script is listening if more data is coming and doesn't close the file, so it is unaccessable.But I don't understand that Functions and its winapihandles so i couldnt test around with it more. Also if i would have known how i can make the program stop listening after x bytes or a specific time, i could make the script still run and display an error, if filetransfer didnt work instead of freezing.I have attached DELmE's work on File Transfering, as it is required by the script above.Thank you for reading, i know it is a lot of text._TCPFileTransfer.au3 Edited June 6, 2011 by Clock Link to comment Share on other sites More sharing options...
Tripredacus Posted June 6, 2011 Share Posted June 6, 2011 I would guess there is an error occuring at the line before MsgBox. Even if the data wasn't present in the var in MsgBox it should still come up and say Server. Can you confirm that TCPShutdown() is actually being done? Twitter | MSFN | VGCollect Link to comment Share on other sites More sharing options...
Clock Posted June 6, 2011 Author Share Posted June 6, 2011 (edited) Hello, thanks for your reply! I tryed to confirm if tcpshutdown() is beeing done, but im not sure how i can check, when it freezes before. ive changed the code to this: #include <_TCPFileTransfer.au3> TCPStartup() $sock = TCPListen("<onlineip>",21525) Do $ssock = TCPAccept($sock) Until $ssock <> -1 $rFileRecv = _TCPFileRecv($ssock, "test.zip") If @error Then Exit ;MsgBox(0,"Server",$rFileRecv) TCPShutdown() MsgBox("","",@error) It doesn't show any of the error returns and also doesn't exit in the If. So the problem is this line? $rFileRecv = _TCPFileRecv($ssock, "test.zip") I also tryed to do it all by myself, because I'm not good enough with AutoIT to fix the UDF myself if that is the problem. TCPStartup() $sock = TCPListen("<onlineip>",21525) Do $ssock = TCPAccept($sock) Until $ssock <> -1 While 1 $get = TCPRecv($ssock, 2048, 1) If StringLen($get) > 100 Then ExitLoop WEnd $test = FileOpen("D:\test.zip", 16) FileWrite($test, $get) FileClose($test) MsgBox("","Done","Sucess") ;$rFileRecv = _TCPFileRecv($ssock, "test.zip") ;MsgBox(0,"Server",$rFileRecv) TCPShutdown() All it does is displaying the last message box when i send data. it doesn't save anything to file. Edited June 6, 2011 by Clock Link to comment Share on other sites More sharing options...
Tripredacus Posted June 6, 2011 Share Posted June 6, 2011 I think maybe you need to check to see if the object exists? http://www.autoitscript.com/wiki/IsObj Twitter | MSFN | VGCollect Link to comment Share on other sites More sharing options...
Clock Posted June 6, 2011 Author Share Posted June 6, 2011 (edited) I just realised that other people have the same problem, too. I didn't read the UDF Authors thread fully, at the end someone has the exact same problem with the filehandle.. It would be best for me to try finding out how it works without UDF.. If anyone has any ideas, i posted what i have so far in the second script in the post 2 above. Help with that would really be appreciated EDIT: Comment to my script: With If StringLen($get) > 100 Then ExitLoop i just wanted the script to quit after 100 bits have been sended, just to check if he writes something to the file I found various example scripts and UDFs and such in this forum and on the internet and it should work like that: 1) Open a file in binarymode 2) Read the file (when i msgbox the variable, it seems to be binary now) and close the file afterwards 3) send the data to the server 4) server puts data in a variable 5) i open a new file with file open in binary mode 6) write the data with filewrite to the file 7) close the file 8) file should be okay? Hope someone can put me on the right track here (do i miss a step??) or could anyone show me the correct way to accept that traffic and save it? So that i can learn from it Edited June 6, 2011 by Clock Link to comment Share on other sites More sharing options...
Tripredacus Posted June 6, 2011 Share Posted June 6, 2011 Does this one from last week help at all? It uses a different UDF tho. Twitter | MSFN | VGCollect Link to comment Share on other sites More sharing options...
Clock Posted June 7, 2011 Author Share Posted June 7, 2011 I finally made it If anyone else is interested in learning about file transfer over TCP, then just use this thread for good example: Also thank you for the help TripredacusThe mistake that i made was that my script didn't read and send the file fully on the sender side.. and then on the receiver end it didn't write the file fully..I had to read/transmit/receive/write the data in WHILE Link to comment Share on other sites More sharing options...
HCAZ Posted June 13, 2011 Share Posted June 13, 2011 Hello, this script works perfectly with no changes. The only problem with it is in the "RECEIVER" it has a icon in the task bar, is there anyway to take this icon off so it will run unnoticed? 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