Page 1 of 1

ReceiveNetworkFile creates 0 byte file?

Posted: Tue Feb 03, 2004 4:41 am
by Mortamer
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).

Posted: Tue Feb 03, 2004 6:40 am
by Paul
Works fine here so maybe you have a problem in your code. No way to know since you didn't post anything.

Best thing to do is look in the PureBasic\Examples\Sources at NetworkServer.pb and NetworkClient.pb examples.

Posted: Wed Feb 04, 2004 4:20 am
by Mortamer
its so simple I didnt think I needed to, but heres the client code:

Code: Select all

InitNetwork()
CID = OpenNetworkConnection("127.0.0.1", 3869)
Delay(5000)
ReceiveNetworkFile(CID, "C:\testFile.exe")
Its goal is to connect to the server, and when the server gets connected to, it sends a file.

Posted: Wed Feb 04, 2004 11:20 am
by Anden
1) You're openening a network connection to yourself (via loopback interface 127.0.0.1) and not to your friend.

2) Don't mess with delay's if there is any other option. Ever thought about a message loop :-)?

Posted: Wed Feb 04, 2004 12:59 pm
by coma
You have to use NetworkClientEvent().
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()
CLIENT :

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)
theoretically it should work...