Is there anyway that will allow to get all data sent via tcp before the session gets closed?
You keep reading data from the socket till EOF
is received.
What I am getting is I have to close the session from server only after that data is received
Technically, one can close your write side of the TCP connection, using shutdown(socket, SHUT_WR)
indicating that this peer is not going to send any more data. But it will still need to read all the data till EOF
is seen and then close(socket)
.
and moreover I have to manually pass EOL or carriage-return or "\n" or "\r"
This has little to do with sockets or TCP, rather with a higher application protocol, such as HTTP. There are libraries available for this popular protocol that simplify this task.