NIO How to send many requests to a site,using(opening)only one connection?

Hello everybody,

I begin to work with java.nio. Here is description about my program: The client open one connection to a site, using NIO ( SocketChannel, configureBlocking(false) ).

After finish connection, the client send request to server and wait for read data. After reading (read to the end of file transfer) the client try to send the other request to server. The first request is successful but the second is not. The client cannot send more than one request on the same connection. (I verified that the server didn't receive any other request, although the client had sent it)

What's wrong here? It means to send a sequence of requests to the same server, we need close the connection after the previous request, and than open again to send the next request, and continue by that way? I think it's wrong because it wastes time and resources to open/close socket (SocketChannel) to the same site.

Please tell me HOW to send many requests to a site, using only one SocketChannel, needn't close/open each time of request.

Thank you very much.

[1092 byte] By [nightingalea] at [2007-11-27 6:49:17]
# 1
Crossposted and answered in the Networking forum
ejpa at 2007-7-12 18:22:56 > top of Java-index,Core,Core APIs...