Which is the best method for sending a data using sockets:
Method 1: Creating a new socket every time when data needs to be sent and closing it when the transfer is
It depends on the kind of socket, but in the usual cases it is better to keep the socket unless you have very limited resources.
In summary: If you are using TCP you almost always better keep the socket open and close it only if you lack the necessary resources to keep it open. A good compromise is to close the socket as long as you have enough activity on the socket. This is the approach usually done with HTTP persistent connections.