Question Send File with a socket chat application

peyman677

New member
Joined
Jul 25, 2013
Messages
1
Programming Experience
3-5
hi, the attached source is a chat application using socket. how can change the source to have a chat application with send file Option? thanks.
 

Attachments

  • chat.zip
    17.1 KB · Views: 26
Last edited by a moderator:
I'm not about to download your attachment because, as far as I'm concerned, downloading an entire project should be a last resort. I will answer your question in principle though.

When you send data, it's all Bytes. No matter what you send, you have to convert it to Bytes first and then, at the other end, you convert those Bytes back to whatever they are supposed to represent.

You need to first decide on a protocol. If you want to send different types of data, e.g. text messages and files, then I would suggest that each transmission should start with a numeric code that tells the receiver what's coming next. For a file, you would follow that by the size of the file and maybe the file name. That would be followed by the contents of the file itself. To get a Byte array to send from the file you could call File.ReadAllBytes or you could use a FileStream and read blocks in a loop.
 
Back
Top