Questions tagged [socketchannel]

Issues related to socket channel for stream-oriented connecting sockets in Java

A socket channel represents a "selectable channel" for stream-oriented connecting sockets in Java. It is part of the Java NIO library.

249 questions
1
vote
1 answer

Getting java.nio.channels.CancelledKeyException without explicit cancellation of the key

I have been getting Getting java.nio.channels.CancelledKeyException thrown from: at sun.nio.ch.SelectionKeyImpl.ensureValid(SelectionKeyImpl.java:55) at sun.nio.ch.SelectionKeyImpl.interestOps(SelectionKeyImpl.java:64) However, I am not calling the…
Eitan
  • 494
  • 5
  • 10
1
vote
1 answer

Java nio server client asynchonous

I made a server myself using java nio and a selector. I can receive the data and answer directly from the client if needed. But now I want a thread that will process data, and anytime it will send data to each client. So how can I do that? Also how…
kinaesthesia
  • 703
  • 6
  • 27
1
vote
1 answer

Java nio Reading SocketChannel on a Selector

I have a small server application which receives connections from multiple clients. The clients will connect, send a message and disconnect, there is no response sent back. I'm using a ServerSocketChannel to listen for connections. I get notified of…
jasg
  • 182
  • 2
  • 10
0
votes
1 answer

is Java SocketChannel write(ByteBuffer source) in Android different in windows?

When i debug code contain SocketChannel write in Android, i got IllegalArgumentException, but the same code in windows no this exception, is there difference between Android and windows in SocketChannel write ? UPDATE : (the code is part of open…
ghost
  • 458
  • 6
  • 11
0
votes
1 answer

Concurrent read() of separate SocketChannels slow for large ByteBuffers

I have written a Java server for remote storage (an iSCSI Target). The client can write data by sending sequences of packets carrying the data payload. These packets consist of a fixed-length header (48 bytes) followed by a variable-length data…
andreas
  • 31
  • 3
0
votes
2 answers

Reading information from a nonblocking SocketChanel

I'm trying to read a nonblocking socket to avoid getting stuck at some point in my program. Does anyone know why when I try to read always return zero? It would be a problem with ByteBuffer? This problem occurs in the read method with lenght is…
0
votes
1 answer

Convert a blocking Socket object to a SocketChannel's socket?

This might sound weird. I have created a game server based on a thread per socket structure (yes, only one thread per user; responses are sent to clients by worker threads). The thread that I spawn first authenticates the user and handles log-in,…
firemeaway
  • 68
  • 6
0
votes
2 answers

SocketChannel.write() in a single thread processing multiple clients

my application has a queue with " outgoing network packets" (A POJO with a ByteBuffer and a SocketChannel) inside, consumed by a single thread that writes the data to the SocketChannel. I do this to guarantee that every client that should receive…
AndrewBourgeois
  • 2,634
  • 7
  • 41
  • 58
0
votes
0 answers

Handling realtime events flutter provider package

I'm developing a project which is somewhat large and I'm facing difficulty on implementing realtime events happening on the server. I'm using provider package, across the project and I'm having two providers with something common I mean like posts…
0
votes
0 answers

How to properly handshake in java using nonblocking socketchannels from the JSSE library?

I'm struggling to understand how to establish secure communication (the handshake) between a client and server using the JSSE library. I've read the documentation and have understood the first few parts partially: create an SSLContext -…
Theodore
  • 11
  • 2
0
votes
0 answers

java socketChannel::finishConnect throws NoConnectionPendingException even though connect has been successful

I have the following Java code: class TestClient { ... SocketChannel channel = SocketChannel.open() channel.configureBlocking(false) SelectionKey key = channel.register(clientSelector, SelectionKey.OP_CONNECT) …
Shivani S
  • 17
  • 3
0
votes
0 answers

Maintaining a list of SocketChannels that are unique

I am using Java NIO and selectors to get instances of SocketChannels. I need to attach each instance of a SocketChannel that I get from the selector to an encryption key that is unique to each SocketChannel instance. So I would like to keep a…
Matthew
  • 3,886
  • 7
  • 47
  • 84
0
votes
0 answers

It's possible with a non-blocking SocketChannel to read all present buffered data while preventing further receiving from clients?

The use case is, in an only reading server, when a shutdown request is received to prevent clients to send more data but do the best effort to process possible data in buffers. I've tried with shutdownInput() and socket.close(), which successfully…
lujop
  • 13,504
  • 9
  • 62
  • 95
0
votes
0 answers

Is there any way to know standard errno when socketchannel throws exception?

I am trying to convert some python code to java, I noticed that python socket api is so basic that we can handle some system errorno like import socket import errno socket.socket(socket.AF_INET,…
RTM
  • 163
  • 1
  • 9
0
votes
1 answer

Java Asynchroussocketchannel.read using future problem

I am trying to create an application where my client program reads the message from echo server. I'm trying to use Future to read the message from the server that will have a larger size than my allocated bytebuffer. My thought is to read into a…