If you are using some kind of protocol (for example HTTP), the protocol should clearly state where does data begin or end. If you implement your own protocol, provide your own means to determine that. If you're using HTTP, you might find using QHttp instead of lower level socket classes convenient.