My Design
I'm using sockets to implement a chat server.
The client side uses Java's java.net.Socket and BufferedReader to read messages from the server.
The server side uses Php's socket_read() to get messages from the clients.
And it uses Php's socket_write() to send messages from the server. socket_write() does not guarantee that the entire original message will be written out, which means I may have to make multiple calls to it to send out the entire original message.
(In terms of design, clients send messages to the server, and server reroutes those messages to the appropriate clients.)
Concerns
My concerns are that a message may be broken up into several smaller messages. So when the server or a client reads an incoming message, it may actually be a fragment of the original.
Questions
Is this something I need to account for? If yes, how?
Possible Solution
Right now I'm thinking about using byte stuffing (which is a networking technique to insert bytes into the original message that serve as flags to mark the start and end of a message before sending it out).