The path is to design a communication protocol first before you start network programming.
How should I know? It's your server not mine. If you claim the receiving end should be the same then I'll say that the sending end should be the same as well. However I have no idea how you wish to display an image file as text in the chat window.To my knowledge, the server should receive and send the "chat message" in the same way like a file, the only difference being th esize of each. PLease corect me if I am not correct.
Bookmarks