Jump to content

The first File Over TCP function


GtaSpider
 Share

Recommended Posts

  • 1 month later...

Read this whole topic and if you can't get it to send a file, maybe I can squeeze out some time to help.

http://www.autoitscript.com/forum/index.ph...st&p=567406

Lar.

ok i have my script now working. the file send and recieve works now i have some questions.

i want to sent a file, but the problem is that the file is gettings bigger for a while maby when the file get sendet the file gets bigger

the upcoming 30 min.

eatch seconds the file get some bits larger

i want that that the connections stays open and the sendig does not stop until the server say so

so when the file is not gettings bigger hold the tcp connection open and hold the tcp recieve open until the file on the server side dont get bigger anymore then send a command that the client know that the transmission is done

can somebody help me on that?

this is my code

server

#include<_FileSend.au3>
$g_IP = "127.0.0.1"
TCPStartUp()
$MainSocket = TCPListen($g_IP, 65432,  100 )
If $MainSocket = -1 Then MsgBox(4096, "Test", @error)
While 1
$ConnectedSocket = TCPAccept( $MainSocket)
If $ConnectedSocket >= 0 Then
_FileSend(@DesktopDir&"\naamloos.JPG", $ConnectedSocket)
EndIf
Wend

#include<_FileRecieve.au3>
$g_IP = "127.0.0.1"
TCPStartUp()
$socket = TCPConnect( $g_IP, 65432 )
If $socket = -1 Then Exit
ConsoleWrite($socket)
_FileRecieve(@MyDocumentsDir&"\tcp.jpg", $socket)
If @error Then MsgBox(48,"","Error: "&@error)
Link to comment
Share on other sites

Hello

Uhm, so you have to rewrite my complete FileSend UDF.

You have to reread the file each second (or what ever)

My UDF only reads the File in the Memory and send it.

Why you dont Send the File and after _FileSend u check whatz new in the File and then u write the offcut in a new file and send this file.

Spider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

Hello

Uhm, so you have to rewrite my complete FileSend UDF.

You have to reread the file each second (or what ever)

My UDF only reads the File in the Memory and send it.

Why you dont Send the File and after _FileSend u check whatz new in the File and then u write the offcut in a new file and send this file.

Spider

cause when the clinet is recieving its already reading ethe file out,... so i cant resend it from server when it getting bigger on the server it needs to stay sending hold the connection open if ont he server the file is getting bigger then send and add that data on the client when it not getting bigger for one sec just wait and continue.... is this possebel he stopt when the server close the socket so send exit or quit or just kick the client by closesocket

Link to comment
Share on other sites

I'm having trouble understanding this line of code!!

$sBuff = BinaryMid ($sBuff, $iSendReturn + 1, BinaryLen ($sBuff) - $iSendReturn) ;set the buffer to nothing?
                ;Extracts a number of bytes from a binary variant, from the file, starting at filesize + 1, extracting BinaryLen($sBuff) - $iSendReturn (nothing?)

I commented what I thought it was doing, am I right?

Why not just set $sbuff = "" ??

haha, i just started thinkign about it, thats a nice feature.

If it doesn't send the whole file you subtract what you've already sent, and send the rest in the loop!

Edited by Glyph

tolle indicium

Link to comment
Share on other sites

nice script dude.... though it works only for direct connection with AU3 servers....

[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Link to comment
Share on other sites

  • 10 months later...

; _FileSend($sFile, $iMainSocket)
;
;   $sFile = Path to the file to send
;   $iMainSocket = Socket (from TCPConnect or TCPAccept)

Func _FileSend($sFile, $iMainSocket)
    Local $sBuff, $iFileOp,$sRecv
    
    $iFileOp = FileOpen($sFile, 16)
    If @error Then Return 0
    $sBuff = Binary(StringTrimLeft($sFile,StringInStr($sFile,"\",-1,-1))&",")&FileRead($iFileOp)
    
    Do
    While BinaryLen($sBuff)
        $iSendReturn = TCPSend($iMainSocket, $sBuff)
        If @error Then Return 0
        $sBuff = BinaryMid ($sBuff, $iSendReturn + 1, BinaryLen ($sBuff) - $iSendReturn)
    WEnd
    $sBuff = FileRead($iFileOp)
    Until @error = -1
FileClose($iFileOp)
    Return 1
EndFunc
The Recieve function wont even know the difference. I think. Also, i am posting this from a school computer. Although i have installed autoit, i do not have another computer to test this on ATM, so if someone would test this and perhaps let me know of any bugs, it would be most appreciated.(all credit for this script[minus my little change] goes to the creator on page 1, whatever his name is.)

Edited by LeoPennworks
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...