Wb-FreeKill Posted June 27, 2005 Share Posted June 27, 2005 (edited) I want to read a txt file, and send all it's information with TCPSend.. got it to work, but it wont send the whole txt file, only 3:4 of it.. I raised the buffer, but i don't think thats the right way, so how do i make sure all the txt is being sent and recieved? nomatter the txt file size $Read = FileRead ($LogFile,99999) TCPSend($ConnectedSocket,$Read) Edited June 27, 2005 by Wb-FreeKill Link to comment Share on other sites More sharing options...
roy Posted June 27, 2005 Share Posted June 27, 2005 (edited) TcpSend() function returns the number of bytes sent. Loop until you send a number of bytes equals to file size. Do the same on the client side with TcpRecv(). Roy Edited June 27, 2005 by roy Link to comment Share on other sites More sharing options...
Wb-FreeKill Posted June 27, 2005 Author Share Posted June 27, 2005 TcpSend() function returns the number of bytes sent.Loop until you send a number of bytes equals to file size. Do the same on the client side with TcpRecv().Roy <{POST_SNAPBACK}>okay thanks Link to comment Share on other sites More sharing options...
Wb-FreeKill Posted June 27, 2005 Author Share Posted June 27, 2005 (edited) hmm can't figure this out If FileExists($LogFile) Then $LogSize = FileGetSize($LogFile) $LogRead = FileRead($LogFile,$Buffer) Do $LogSend = TCPSend($socket,"2," & $LogRead) Until $LogSend >= $LogSize msgbox(0,"Bytes send",$LogSend) EndIf Edited June 27, 2005 by Wb-FreeKill Link to comment Share on other sites More sharing options...
Wb-FreeKill Posted June 27, 2005 Author Share Posted June 27, 2005 (edited) perhaps...If FileExists($LogFile) Then $LogSize = FileGetSize($LogFile) $LogRead = FileRead($LogFile,$LogSize) $LogSend = TCPSend($socket,$LogRead) msgbox(0,"Bytes send",$LogSend) EndIf<{POST_SNAPBACK}>my mistake about the "$Buffer", but this will just try to send the whole txt file right? im not recieving the whole thing on the other side... i had to send it in piecees right? like roy said.. sry, im so stupid with this kind of stuf Edited June 27, 2005 by Wb-FreeKill Link to comment Share on other sites More sharing options...
MSLx Fanboy Posted June 27, 2005 Share Posted June 27, 2005 Just do a StringLeft() (I think, that or right) the number of bytes that successfully went through. Writing AutoIt scripts since _DateAdd("d", -2, _NowCalcDate()) Link to comment Share on other sites More sharing options...
Wb-FreeKill Posted June 27, 2005 Author Share Posted June 27, 2005 (edited) Okay figured something out... im posting what i am doing, hope you guys can help me, ive tried - but i can't see what to do, surely it's very simple! TreeClient.au3 TreeServer.au3 Edited June 27, 2005 by Wb-FreeKill Link to comment Share on other sites More sharing options...
Wb-FreeKill Posted June 27, 2005 Author Share Posted June 27, 2005 From what i understand, the TCPSend on Clinet sends it all, but the TCPRecv only takes some of it, thats bacause of the buffer size.. should i just give it a very large number, or how do i split that txt up? Link to comment Share on other sites More sharing options...
Fur Posted June 27, 2005 Share Posted June 27, 2005 From what i understand, the TCPSend on Clinet sends it all, but the TCPRecv only takes some of it, thats bacause of the buffer size.. should i just give it a very large number, or how do i split that txt up?<{POST_SNAPBACK}>Well it would be nice if it was that simple, but if you send 2000 bytes, it's perfectly legal to show up on the client side as 1000 two byte packages. You have to accumulate the incoming data by hand and pack it into your buffer manually.In the same vein as others pointed out above, sending may not send the entire amount all at once for various reasons, and you'll have to adjust your starting point and size accordingly and keep sending until you've sent the entire amount.It's a pain, but it's the only way to get 100% reliable socket communication. Link to comment Share on other sites More sharing options...
MSLx Fanboy Posted June 27, 2005 Share Posted June 27, 2005 That's just some psuedocode, and may or may not work for what you want, that's all I can think of actually getting it to send all of the information $x = 0 While Not $x $sentsize = TCPSend($socket, $text) If $sentsize <> FileGetSize($textfile) Then $StringTrimLeft($text, $sentsize);;check syntax that may not be right Else $x = 1 EndIf WEnd Writing AutoIt scripts since _DateAdd("d", -2, _NowCalcDate()) 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