delphi - File Transfer using winsock -


i want send files(text or binary) through winsock,i have buffer 32768 byte size, in other side buffer size same,but when packet size <32768 don't know how determine end of packet in buffer,also binary file seems mark end of packet unique character not possible,any solution there? thx

with fixed-size "packets," every packet except last full of valid data. last 1 "partial," , if recipient knows how many bytes expect (because, using davita's suggestion, sender told file size in advance), that's no problem. recipient can ignore remainder of last packet.

but further description makes sound there may multiple partially full packets associated single file transmission. there easy solution that: prefix each packet number of valid bytes.

you later mention tcustomwinsocket.receivetext, , wonder how knows how text read, , quote answer, calls receivebuf(pointer(nul)^, -1)) set length of result buffer before filling it. perhaps didn't understand code doing. it's easier understand if @ same code in context, receivelength method. makes same call receivebuf, indicating when pass -1 receivebuf, returns number of bytes received.

in order work purposes, cannot send fixed-size packets. if send 32kb packets, , pad end zeroes, receivelength return 32768, , you'll have combine davita's , solutions of sending file , packet lengths along payload. if ensure every byte in packet valid, recipient can know how save based on size of packet.

one way or another, need make sure sender provides recipient information needs job. if sender sends garbage without giving recipient way distinguish garbage valid data, you're stuck.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -