Page 1 of 1
Send Network File - Can It Be Done - SIMPLY?
Posted: Mon Jan 26, 2004 10:19 pm
by johnfermor
Hi again
Can a LARGE file be sent over over the LAN using TCP/IP?
I have looked through the articles in the forum and have come to the conclusion that the SendNetworkFile/ReceiveNetworkFile commands doesn't work with large files (& locks program executiuon) and of the limited samples I have found, you need to be a rocket scientist to work them out!
Someone must be sitting on an easy-to-understand example which does some basic error handling, progress indication, etc.
I can't be the only person who could use this..
Thanks ..
Posted: Mon Jan 26, 2004 11:44 pm
by Dreglor
yeah it not very hard...*opens pure basic and starts coding*
Posted: Tue Jan 27, 2004 8:48 am
by johnfermor
Well thank you so much for that gem of knowledge...
Posted: Tue Jan 27, 2004 10:03 am
by plouf
you dont specify what is what you didn't understand
basically if you wand to send a large file (larger that 512bytes

)
split it in packets and send every packet separate the is the change
that the buffer from the receiver is overflowed (

) so maybe implement
a custom "acknowledge" i.e. send a packet to client and wait for the client to reply to you with a "OK" then send next packet and so
Posted: Tue Jan 27, 2004 12:18 pm
by coma
I'm trying to make a network file sender too.
a custom "acknowledge" i.e. send a packet to client and wait for the client to reply to you with a "OK" then send next packet and so
That is exactly what I do.
Actually, I send packets of 1000 bytes.
I send it, once received, I send a message to ask for the next packet, and so on.
But it's very slow (particularly with a long ping time).
I have made some tests, asking for a "receive confirmation" every 5 packets for exemple, but sometime this crash.
Posted: Wed Jan 28, 2004 8:07 pm
by nessie
Can't you just use FTP to send the file?
Posted: Wed Jan 28, 2004 8:26 pm
by johnfermor
I may have to. I just wanted to try and get around the Send/ReceiveNetworkFile procedures. Thanks anyway..
Posted: Wed Jan 28, 2004 9:38 pm
by kenmo
Well I dunno about actually sending the file, but to avoid locking the program cant you send the file through a thread?
Posted: Thu Jan 29, 2004 2:13 am
by coma
the problem is not to lock the program, but to synchronise the sender and the receiver.
Re: Send Network File - Can It Be Done - SIMPLY?
Posted: Thu Jan 29, 2004 9:20 am
by Anden
johnfermor wrote:
Someone must be sitting on an easy-to-understand example which does some basic error handling, progress indication, etc.
Thanks ..
Well, not exactly what you want (no progress indication which is desperately missing from SendNetworkFile *HINT*). But hey, it's a start
Be aware that sending files larger than 32 MB doesn't work very well (so don't even try)
Example procedure sends the program exe itself to the receiver and is designed to run as a thread (hence the "thread-safe" parameter-field).
Code: Select all
Procedure TransferExe(para.l)
usr.s = StringField(ThreadXTransfer, 1, cr)
rIP.s = StringField(ThreadXTransfer, 2, cr)
File$ = Space(512)
GetModuleFileName_(GetModuleHandle_(#NULL), @File$, 512)
CID = OpenNetworkConnection(rIP, serv\Port)
If (CID)
EnableWindow_(WindowID(#client), #False) ;one file after the other!
ServerMess("** Sending new client version "+MakeVerStr(#VER)+" to "+usr+cr+"** Please be patient ... ("+CurrentTime()+")")
SendData(CID, cfile+client\name+cfile+GetFilePart(File$))
Delay(200) ;wait 4 recipient to receive "announce" string
SendNetworkFile(CID, File$)
ServerMess("** Finished sending "+Str(FileSize(File$))+" Bytes ("+CurrentTime()+")")
StatusBarText(#StatBar, 3, "New client has been sent to "+usr+" ("+CurrentTime()+")")
CloseNetworkConnection(CID)
Delay(200) ;fucking wait a bit - big files need time to receive
EnableWindow_(WindowID(#client), #True)
EndIf
EndProcedure
ReceiveNetworkFile() is not slightly thread-safe, so DO NOT call RecFile() as a thread or if RECSTAT = #True! (progress indication could make my day here, too)
Code: Select all
Procedure RecFile(filname.s, CID.l, usrnam.s)
If (usrnam > "" And CID > 0)
RECSTAT = #True
SendDataServer(serv\CID, cnofilerec+"1") ;i'm busy receiving a file, dont' disturb
If (filname = "") : filname = "Unnamed"+FormatDate("%yyyy%mm%dd-%hh%ii%ss", Date())+".xxx" : EndIf
ServerMess("** Getting file <"+filname+"> from "+usrnam+" ("+CurrentTime()+")")
DeleteFile(HomeDir+"Transfer"+filname) ;just to be sure
ReceiveNetworkFile(CID, HomeDir+"Transfer"+filname)
ServerMess("** Received "+Str(FileSize(HomeDir+"Transfer"+filname))+" Bytes ("+CurrentTime()+")")
StatusBarText(#StatBar, 3, "Received file "+filname+" from "+usrnam+" ("+CurrentTime()+")")
NEWDATA = #True
HandleFile(filname)
If (FSHALT = 0) : SendDataServer(serv\CID, cnofilerec+"0") : EndIf ;ready 4 more (and filerec still enabled)
RECSTAT = #False
Else
WriteLOG(#True, "Unknown file sent from "+usrnam)
EndIf
EndProcedure
Hope i could help
ciao
Anden
Posted: Thu Jan 29, 2004 7:55 pm
by johnfermor
Thanks Anden
I'll give this a try and see If I can adapt it to my own needs. This at least gives me the starting point I've been looking for. Thanks for your efforts - much appreciated.
John