N
nooneinparticular314159
I'm trying to read some data from a channel using java NIO. I create
a connection successfully, and then I try to read from the channel,
but I get the following error:
java.lang.ClassCastException: sun.nio.ch.ServerSocketChannelImpl
The following is the code that results in the error:
SocketChannel Channel;
public ChannelReader(ByteBuffer ReceiveBuffer, SelectionKey InputKey)
{
this.ReceiveBuffer = ReceiveBuffer;
this.key = InputKey;
try {
Channel = (SocketChannel) InputKey.channel();
} catch (Throwable Exception) {
System.out.println("ChannelReader: ChannelReader:" +
Exception);
}
}
The error occurs on the line: Channel = (SocketChannel)
InputKey.channel();
What is causing this? How can I fix it?
Thanks!
a connection successfully, and then I try to read from the channel,
but I get the following error:
java.lang.ClassCastException: sun.nio.ch.ServerSocketChannelImpl
The following is the code that results in the error:
SocketChannel Channel;
public ChannelReader(ByteBuffer ReceiveBuffer, SelectionKey InputKey)
{
this.ReceiveBuffer = ReceiveBuffer;
this.key = InputKey;
try {
Channel = (SocketChannel) InputKey.channel();
} catch (Throwable Exception) {
System.out.println("ChannelReader: ChannelReader:" +
Exception);
}
}
The error occurs on the line: Channel = (SocketChannel)
InputKey.channel();
What is causing this? How can I fix it?
Thanks!