|
A communication program. One of my classes uses NIO to obtain data from the gateway and then combines the data. After processing, the global variable is passed to another class through a String. This class writes this string into NIO through NIO. Get the Channel, and the client gets the string variable from the Channel through NIO. However, a delay occurred about 8 minutes after this operation.
If I don't write the string variable to the client, there will be no delay ~~~~~~~~~~~~~~~
What's going on ~~~~~~~~~~~~
public void writeToChannel (SocketChannel channel, String message) throws IOException {
// System.out.println ("write");
int x = channel.socket (). getSendBufferSize ();
ByteBuffer buf = ByteBuffer.allocateDirect (x);
buf = ByteBuffer.wrap (message.getBytes ());
// ByteBuffer buf = ByteBuffer.wrap (message.getBytes ());
// int nbytes = channel.write (buf);
channel.write (buf);
buf.clear ();
channel.close ();
}
It is written into the Channel through this method. Is there anything wrong? ? ? |
|