Hello,
Excuse me, but when you say that you execute the query from a dos box, is it by executing your program from the dos box ? If not, what do you mean by dos box (you must use a connection to the mysql server) ? Concerning TCP/IP and sockets, it seems odd to me that there were two such modes, for from a socket, you can choose to use several protocols such as TCP/IP or UDP, but the two seem independant to me (except if they speak of special sockets...). I think your program must use a TCP connection (through a socket). So, one thing you can do is disabling the TCP_NO_DELAY option when you connect to the server. Check if this is possible (this would force the query to be sent to the server immediately). This is a network connection improvement. Now, something else you can try in your program is to "prefetch" results in your resultset, and read several rows at a time instead of one (something like a next(30) compared to a next()) because that would minimize the number of calls to the server (for 4000 rows, you would do 134 calls instead of 4000) which would dramatically reduce network traffic. However, such optimizations are not possible though all APIs. I mainly work on Oracle with the OCCI and JDBC APIs. If you develop using JDBC, you can do this by using the setFetchSize(int rows) method. For now, I don't see another reason why you have such a problem.
I hope this will help you,
Regards,
RBARAER