ReceiveNetworkFile creates 0 byte file?

Just starting out? Need help? Post your questions and find answers here.
Mortamer
User
User
Posts: 36
Joined: Mon Dec 29, 2003 5:07 pm

ReceiveNetworkFile creates 0 byte file?

Post 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).
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1285
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post 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.
Image Image
Mortamer
User
User
Posts: 36
Joined: Mon Dec 29, 2003 5:07 pm

Post 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.
Anden
Enthusiast
Enthusiast
Posts: 135
Joined: Mon Jul 21, 2003 7:23 am
Contact:

Post 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 :-)?
coma
Enthusiast
Enthusiast
Posts: 164
Joined: Fri Aug 15, 2003 3:46 am
Location: Canada

Post 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...
Post Reply