Page 1 of 1

Send/Receive NetworkFile commands

Posted: Mon Apr 27, 2009 5:00 pm
by endo
Hi, Fred, could you please explain the method using by Send/ReceiveNetworkFile functions?
I know they should be reliable but how do we know that really? espacially if we get errors?
There is just true/false result means success or fail. But no help why it fails? Is it read the whole file into memory or not? What is the timeout value for one packet? If Recv can't get a packet, does the Send func. send the same packet again? etc.
I mean, we really need more explanations for these functions.

I know, someone can say, if it doesn't work, write your own transfer functions. I know that option, but I also want to know about these functions.

here is my test applications:

sendfile (client)

Code: Select all

;
; SendFile
;
If OpenConsole() And InitNetwork()
	If CountProgramParameters() = 3
		C.l = OpenNetworkConnection(ProgramParameter(1),Val(ProgramParameter(2)), #PB_Network_TCP)
		If C
			If SendNetworkFile(C,ProgramParameter(0))
				PrintN("Sent successful.")
			Else
				PrintN("Error sending file.")
			EndIf
			CloseNetworkConnection(C)
		Else
			PrintN("OpenNetworkConnection failed.")
		EndIf
	Else
		PrintN("usage: sendfile.exe <filename> <ip> <port>")
	EndIf
	CloseConsole()
EndIf
and receive file (server)

Code: Select all

;
; RecvFile
;
If OpenConsole() And InitNetwork()
	If CountProgramParameters() = 2
		C = CreateNetworkServer(0,Val(ProgramParameter(1)),#PB_Network_TCP)

		Repeat
			E = NetworkServerEvent()
			If E
				Select E
					Case #PB_NetworkEvent_Connect
						PrintN("New Client Connected")
					Case #PB_NetworkEvent_File
						C = EventClient()
						If ReceiveNetworkFile(C,ProgramParameter(0))
							PrintN("Receive successful.")
						Else
							PrintN("Error receiving file.")
						EndIf
				EndSelect
			Else
				If Inkey() = Chr(27)
					CloseNetworkServer(0)
					CloseConsole()
					Break
				EndIf
				Delay(10)
			EndIf
		ForEver
		
	Else
		PrintN("usage: recvfile.exe <filename> <port>")
	EndIf
	CloseConsole()
EndIf
use them from dos command prompt:
recvfile.exe test.txt 1234

sendfile.exe hugefile.txt 127.0.0.1 1234 (from another console)

it works for small files, even for 100 mb files. but fails for over 170 mb files (fails everytime, not sometimes.)
My pc has 2 gb ram, I can open that huge file with a text editor, so it should not be related to memory size. (at least directly..)

I'm using pb 4.30 on XP Pro, testing on localhost.
best regards.

Posted: Mon Apr 27, 2009 5:51 pm
by AND51
These commands are not relieable and I am not the only one who encountered this problem.
iirc, Fred wants to abolish these commands in some of the next versions. Instead, he recommends to send files manually via SendNetworkData().