Jump to content

TCPSend($TxtFile)


Recommended Posts

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
Link to comment
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 :)

Edited by roy
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
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())
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...