Large files over NET [SOLVED]

Windows specific forum
LiK137
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Jun 23, 2010 5:13 pm

Large files over NET [SOLVED]

Post by LiK137 »

I want to modify the code to send/receive list of files so the server side does not close connection and continue listen PORT

Here is the code

Code: Select all

;Buffered file transfer with unlimited filesize 
;Server 
;by Inf0Byt3 

; OpenConsole() 

#Command = "!ASLKLK#@*)SAUJ!" 
#DataBuf = "!SI#)()U!J:LSAJ!" 

Global FileHandle 
*Buffer = AllocateMemory(1024) 


If InitNetwork() 
CreateNetworkServer(0, 6443, #PB_Network_TCP) 
Debug("Server created...") 
Repeat 
SEvent = NetworkServerEvent() 
If SEvent 
ClientID = EventClient() 
Select SEvent 

Case 1 

Case 2 
ReceiveNetworkData(ClientID, *Buffer, 1024) 
Command.s = PeekS(*Buffer,128) 

;00000000000000000000000000000 
Select Left(Command,16) 

Case #Command 
DataRecv.s = Mid(Command,17,Len(Command)-16) 
Filesize.l = Val(StringField(DataRecv,1,"|")) 
Filename.s = StringField(DataRecv,2,"|") 
SavePath.s = StringField(DataRecv,3,"|") 
FileHandle = CreateFile(#PB_Any,SavePath.s) 

Case #DataBuf 
LengthRec = Val(RemoveString(Mid(Command,17,,"X")) 
WriteData(FileHandle,*Buffer+24,LengthRec) 

EndSelect 
FreeMemory(*Buffer) 
;00000000000000000000000000000 

Case 4 
Quit = 1 

EndSelect 
EndIf 
Until Quit = 1 
CloseFile(FileHandle) 
CloseNetworkServer(0) 
Else 
MessageRequester("Error", "Can't create the server (port in use ?).", 0) 
EndIf 





Клиент 

;Client 
OpenConsole() 

#Command = "!ASLKLK#@*)SAUJ!" 
#DataBuf = "!SI#)()U!J:LSAJ!" 

If InitNetwork() = 0 
PrintN("Can't initialize the network !") 
Input() 
End 
EndIf 

;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
File.s = "Source" 
SavePath.s="Destination" 
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 

Global Sent,Length 

ConnectionID = OpenNetworkConnection("127.0.0.1", 6443, #PB_Network_TCP) 

If ConnectionID 

;Repeat 

SendNetworkString(ConnectionID, #Command + Str(FileSize(File))+"|"+GetFilePart(File)+"|"+SavePath.s+"|") 
Input() 
If ReadFile(0,File) 
Length = Lof(0) 

While Sent < Length 
*DataSend = AllocateMemory(1024) 
*Temp = AllocateMemory(1000) 
DataR = ReadData(0,*Temp,1000) 
BufferLength.s = LSet(Str(DataR),8,"X") 
Signature.s = #DataBuf+BufferLength+"!" 
PokeS(*DataSend,Signature) 
CopyMemory(*Temp,*DataSend+24,DataR) 
SendNetworkData(ConnectionID,*DataSend,DataR+24) 
FreeMemory(*Temp) 
FreeMemory(*DataSend) 
Sent + DataR 
PrintN(Str(Sent)+" -> "+Str(Length)+" -> "+Str(x)) 
x + 1 
Wend 

CloseFile(0) 
CloseNetworkConnection(ConnectionID) 
EndIf 
Input() 

Else 
MessageRequester("Client", "Can't find the server!!! Is it launched ?", 0) 
EndIf
Last edited by LiK137 on Tue Jan 10, 2017 11:06 am, edited 1 time in total.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Large files over NET

Post by IdeasVacuum »

Well, the ftp app that I use sends
'Keep Alive' commands such as "PWD", "REST 0", "TYPE A", or "TYPE I" to simulate activity and prevent the FTP server from logging you out.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply