ReceiveNetworkFile creates 0 byte file?
ReceiveNetworkFile creates 0 byte file?
I did a very basic file transfer program because I needed to get a file to my friend (his router screwed up AIM file transfer, etc). It basically just has him connect to me, once he connects I send him the file, (it'll wait like 5 seconds before downloading) and he receives it. Everything works except it makes the file 0 bytes. Is their something wrong with ReceiveNetworkFile? You just do ReceiveNetworkFile(ClientID, WhereToSaveFile$) right? I made a test file thats only 5kb, (a message requester and thats it) so I doubt it overloaded it lol... Its gotta be ReceiveNetworkFile because it obviously connects and everything as it saves the file name (just not the file lol).
its so simple I didnt think I needed to, but heres the client code: Its goal is to connect to the server, and when the server gets connected to, it sends a file.
Code: Select all
InitNetwork()
CID = OpenNetworkConnection("127.0.0.1", 3869)
Delay(5000)
ReceiveNetworkFile(CID, "C:\testFile.exe")You have to use NetworkClientEvent().
Try this :
SERVER :
CLIENT :
theoretically it should work...
Try this :
SERVER :
Code: Select all
OpenWindow(0,0,0,320,240,#PB_Window_ScreenCentered | #PB_Window_SystemMenu, "Sendfile - server")
InitNetwork()
CreateNetworkServer(3869)
Repeat
If WindowEvent()=#PB_Event_CloseWindow : CloseNetworkServer() : End : EndIf
SEvent = NetworkServerEvent()
Select SEvent
Case 1 ; A new client has been connected to the server
ClientID = NetworkClientID()
MessageRequester("PureBasic - Server", "A new client has connected", 0)
file$=OpenFileRequester("Select File", "","*.*", 0)
SendNetworkFile(ClientID,file$)
EndSelect
Until GetAsyncKeyState_(#VK_Escape)
CloseNetworkServer()Code: Select all
OpenWindow(0,0,0,320,240, #PB_Window_ScreenCentered | #PB_Window_SystemMenu,"Sendfile - client")
InitNetwork()
CID = OpenNetworkConnection("127.0.0.1", 3869)
Repeat
If WindowEvent()=#PB_Event_CloseWindow : End : EndIf
CEvent = NetworkClientEvent(CID)
Select CEvent
Case 3 ; A file has been received (to be read with ReceiveNetworkFile())
MessageRequester("PureBasic - Client", "receiving file", 0)
ReceiveNetworkFile(CID, "C:\file.dat")
EndSelect
Until GetAsyncKeyState_(#VK_Escape)




