Send/Receive NetworkFile commands

Everything else that doesn't fall into one of the other PB categories.
endo
Enthusiast
Enthusiast
Posts: 141
Joined: Fri Apr 30, 2004 10:44 pm
Location: Turkiye (istanbul)
Contact:

Send/Receive NetworkFile commands

Post 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.
-= endo (registered user of purebasic since 98) =-
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post 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().
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Post Reply