Sign in to follow this  
Followers 0
Wb-FreeKill

TCPSend($TxtFile)

10 posts in this topic

#1 ·  Posted (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 by Wb-FreeKill

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by roy

Share this post


Link to post
Share on other sites

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  :evil:

<{POST_SNAPBACK}>

okay thanks :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by Wb-FreeKill

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by Wb-FreeKill

Share this post


Link to post
Share on other sites

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())

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by Wb-FreeKill

Share this post


Link to post
Share on other sites

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?:)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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())

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0