Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello guys, can you explain me how to send a file as a string through socket from server to client side and convert the string back into the original file on the client side for further use.
Posted

1. Why send it as a string? Is there any reason why you can't just send it as binary? Maybe need to prefix with a few bytes to give file size so that recipient know when binary file ends.

2. If you need to send a string, maybe convert binary data to text using Base64 encoding / decode it back at the other end.
 
Share this answer
 
Comments
Nish Nishant 30-Apr-11 15:58pm    
Excellent response. My vote of 5!
Sergey Alexandrovich Kryukov 30-Apr-11 23:26pm    
Agree, a 5. One note: as a string without base64 encoding is also possible, can be just UTF-8 (UTF-16 less practical due to volume). Using raw TCP socket imposes no limitation.
--SA
Sergey Alexandrovich Kryukov 30-Apr-11 23:31pm    
I added my answer, please see.
--SA
Use System.Net.Sockets.TcpListener and System.Net.Sockets.TcpClient; this is most convenient way of using sockets for such purpose. Why raw sockets? A higher-level way with using classical remoting or WCF (self-hosted) would also work. A parameter of service contract method will be a file content (as string, if you want, but prefer encoding it the an array of bytes using UTF-8, for performance sake).

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900