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
0
votes
0 answers

Why does client not receive final server answer in non-blocking client-server app?

I am trying to figure out NIO in Java doing some simple client-server project. The case is I have to concurrent clients in cached thread pool executor, who are communicating with single-threaded server using non-blocking NIO channels. The problem is…
magladko
  • 3
  • 3
0
votes
0 answers

Should I cancel the key when SocketChannel#connect returns true?

When SocketChannel#connect returns a true for a selector-registered SocketChannel, should I cancel the SelectionKey? final var client = SocketChannel.open(); client.configureBlocking(false); final var…
Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
0
votes
1 answer

Using two Selectors for NIO

I need a way to use different Selectors for OP_READ & OP_ACCEPT. I am running into an issue where port scrapers among other entities connecting will delay the handshake and cause latency for anyone registered on OP_READ. My solution was to handle…
0
votes
0 answers

AsynchronousSocketChannel result not returning -1 on end-of-stream

I am trying to setup an AsynchronousServerSocketChannel that accepts connections from clients and send and receive messages as needed (not necessarily request->response). To facilitate this, I am using asynchronous read and write calls with separate…
0
votes
0 answers

ServerSocketChannel stops Accepting after a while on Linux

I noticed that, when I run my application on a Linux OS, after a while, the server just stops accepting clients. This is a screenshot of wireshark when trying to connect to the Server from my host, after it stopped accepting. As you can see the…
Stefan
  • 67
  • 9
0
votes
1 answer

Java NIO Issue/Misunderstanding of how isReadable works

I've found that the NIO is poorly documented at best except for the simplistic case. Even so, I've been through the tutorials and several refactors and ultimately pushed back to the simplest case and I'm still occasionally having isReadable firing…
Brian
  • 2,253
  • 2
  • 23
  • 39
0
votes
1 answer

Writing to SocketChannel in Java repeats unexpectedly

I have been trying to work with NIO SocketChannels for some time now, and I am stumped regarding writing out to a SocketChannel. The following code is from my client: public class nbClient { /** * @param args */ static int id; static int…
duanemat
  • 237
  • 1
  • 6
  • 12
0
votes
0 answers

Selector.select() blocks FOREVER but Selector.select(timeout) returns OP_READ instantly

When I use select() without a timeout, it simply hangs forever on select(). But if I use select(long) with a timeout, it does return and allow me to read the data. (prints "read!") The code: package org.nio; import java.io.OutputStream; import…
Colby
  • 452
  • 4
  • 19
0
votes
0 answers

Java SocketChannel cannot send data to ServerSocketChannel

I am trying to write a simple client/server in Java using NIO and Selectors. The server is very easy and it's the most typical implementation that you can find everywhere. Here's the code of the server (look at the start() method): public final…
Paul L
  • 73
  • 7
0
votes
1 answer

SocketChannel.read ( ) got correct data only once and blank

To test sending data with SocketChannel: My Java app uses SocketChannel.write ( ) to keep sending same data repeatedly with a random short delay. Checking the cmdline log, the data is always sent…
BingLi224
  • 452
  • 2
  • 6
  • 12
0
votes
1 answer

Getting ip6 format in getInetAddress()

Will getInetAddress() from a socket return ip in ip4 or ip6 format? I have been receiving ip6 format only for localhost. Are there any machine level changes to address this?
0
votes
1 answer

Java trouble with SocketChannel connections

This is a class assignment, so I need hints more than answers. I have a process running on four virtual linux machines. Each process communicates with two of its neighbors. Each process uses server =…
Kelly Cline
  • 2,206
  • 2
  • 33
  • 57
0
votes
2 answers

How to use SocketChannel to connect to remote webserver

I am trying to get the response sent by the web server through Java NIO socketChannel. The read call of SocketChannel is not returning anything when it is in non-blocking clientSocket.configureBlocking(false); When specified true, means…
pavannpg
  • 41
  • 2
  • 7
0
votes
1 answer

Thread per connection vs one thread for all connections in java

I have two different types of server and clients working at the moment and i am trying to decide which one would be better for an MMO server or at least a small MMO like server with at least 100 players at a time. my first server is using a thread…
Arcxz
  • 65
  • 1
  • 11
0
votes
1 answer

Java nio socketchannel read early eos in safari and IOS with TLS1.2

i have a really weird problem, which i am working on the last couple days. I wrote a proxy application on my serverside. All the proxy does is managing TLS/nonTLS requests and responses from different Applications (WebApplications, IOSApps, Android…
R3tty
  • 39
  • 7