I need urgent help!

Everything else that doesn't fall into one of the other PB categories.
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

I need urgent help!

Post by Inf0Byt3 »

Hi guys, i need some help from you. I am making a network related app but i've got a big big problem. I manage all the events (the network ones and the window ones) in the main loop. I am using the code i posted in the Tips and Tricks section, the one to send/receive files. The problem is the callback of the send/receive procedures. If i don't use the procedures in a thread and call them normally, the window freezes. If i thread them, it works, except for the packet delivery (the received files are incomplete). What can i do to manage the events correctly? Please help!
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post by Dreglor »

could you post some code, it would help explain more about the problem right now i can't heads or tails about it
~Dreglor
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Well, i really cannot show you the code because it's very big (3000+) lines of code and it's all built around this event-handling stuff. It seems that the file transfer loop must be made continuous, because it send the file at once, in one piece. If i add a WindowEvent() in it, it misses packets, so the only thing i can do is to try modify the send/receive procedures. Is there any other solution for this?
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

I know your problem. As I wrote my first network routines I had the same problem.

You need to check the Result of Send_() / SendNetworkData() and recv_() / ReceiveNetworkData().

Send_() sometimes returns a #SOCKET_Error which indicates a blocking host. That means that you have to resend your message again and again till it is completely transfered. Send_() and recv_() also returns the number of bytes transfered. Check for it. In my own Fileprotocol I splitted a file in parts of 4096 Bytes. On sending it, I added a small header to the packet which contains the packet-size so that I know the expected packetsize on the destination side. TCP/IP sometimes splits messages, so you have to call recv_() as long as your data is complete.

Its hardly to say what it's your problem without a source. But this is what you have to check for. Mostly, localhost actions works fine couse the socket is mostly not in blocking state.

Mike
Tranquil
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

\Yup, that's exactly what i wanted to say about this! I allmost done it, except for the fact that SendNetworkData returns -1 in the file transmission loop. That's something i've got to fix :). BTW, is there a chance that you have some procedures for correctly sending/receiving a buffer? I can't make mine work at all :(. Ah, and i found a simple solution for my problem... Pseudocode:

Code: Select all

{ 
  Procedure handleTransfers()
  ;Send the next packet of the file
}

{
;This is the main loop
 Call handleTransfers()
 Do the window handling stuff after handleTransfers() returns
}
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Post Reply