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
4
votes
1 answer

Proper way to read (write) through a SocketChannel

My questions is more generic than the following scenario, though this covers everything needed. It is for Java and the correct practices of socket programming. Scenario: One server with many clients. Usage of non-blocking I/O The server is a client…
4
votes
1 answer

Detecting when ServerSocketChannel closes when in selector.select()

When i have a selector.select() registered to a SocketChannel, and i close the SocketChannel's peer in a separate thread, selector.select() returns, and that channel's READ operation is set. If i have a ServerSocketChannel registered to the…
user9058115
  • 161
  • 5
4
votes
1 answer

Java - Write call to socket output stream blocking in full duplex

I'm writing a client server application and I want to both read and write on one socket from two different threads (one thread for reading, one for writing). I have the system nearly working, but there is one perplexing bug that I can't seem to wrap…
4
votes
2 answers

SocketChannel fires isReadable() but nothing to read

I have got a new problem with my Android app. The SocketChannel tells me that it isReadable() but there is nothing to read. while(running) { int readyChannels = 0; try { readyChannels = selector.select(); }…
Martin
  • 313
  • 1
  • 3
  • 12
4
votes
4 answers

Selector.select() starts an infinite loop

I have a minimal JMS provider, which sends topic messages over UDP and queue messages over TCP. I use a single selector to handle UDP and TCP selection keys (registering both SocketChannels and DatagramChannels). My problem is: if I only send and…
G B
  • 2,951
  • 2
  • 28
  • 50
4
votes
1 answer

How does buffer size affect NIO Channel performance?

I was reading Hadoop IPC implementation. https://github.com/apache/hadoop/blob/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java /** * When the read or write buffer size is larger than this limit, i/o will be…
waltersu
  • 1,191
  • 8
  • 20
4
votes
1 answer

What are the Netty Channel state transitions?

Netty channels have multiple states but I am unable to find any documentation on the actual state transitions. The closest to any documentation on this that I could find for Netty 3.2.x system is here. I was able to locate the possible states that…
Kevin Sitze
  • 8,029
  • 3
  • 16
  • 19
4
votes
1 answer

How correctly close SocketChannel in Java NIO?

I have a simple non-blocking server with main loop: try { while (selector.select() > -1) { // Wait for an event one of the registered channels // Iterate over the set of keys for which events are available Iterator…
sphinks
  • 3,048
  • 8
  • 39
  • 55
3
votes
2 answers

Android - How to keep connection with server for a long time

I wrote a chat application for Android using SocketChannel. It connects successfully with the server and all features work. But after a long time since I logged in (about 2-3 hours), I try to send a chat message again and it fails. In log file,…
Sephiroth
  • 126
  • 3
  • 7
3
votes
2 answers

How can I test if a SocketChannel.read() for a non-blocking channel has finished?

I'm using a function to read bytes from non-blocking SocketChannel (socket from accept()) and from blocking SocketChannel (client side). I'm implementing a server using selector to handle multiple clients, and I'm using loopback address to use my…
Falkon
  • 41
  • 5
3
votes
3 answers

SSL implementation for SocketChannel in java

I am looking at classes of the package java.nio.channels but only finding plain socket implementations. I can use the SSLEngine to encrypt and decrypt traffic, but that would be quite a bit of handling. Anybody knows of a proper…
Arteri Xhafur
  • 39
  • 1
  • 2
3
votes
1 answer

Manage Client Socket Pool

I need to manage long running TCP socket connections to an external server from my Java application. I'm looking for a good socket pool so I will be able to re-use the sockets. There is another solution than org.apache.commons.pool2 ?
Mercer
  • 9,736
  • 30
  • 105
  • 170
3
votes
0 answers

set tcp option on Java ServerSocketChannel

I want to use TCP option : 'TCP_DEFER_ACCEPT' and 'TCP_REUSEPORT' to do something with my java application server. But these option not support by Java socketOptions. so is there a way to set them ? does i need to subclass SocketImpl or supply a…
Chinaxing
  • 8,054
  • 4
  • 28
  • 36
3
votes
1 answer

How do I handle ServerSocketChannel.accept() IOException: too many open files in NIO?

I'm having a problem with one of my servers, on Friday morning I got the following IOException: 11/Sep/2015 01:51:39,524 [ERROR] [Thread-1] - ServerRunnable: IOException: java.io.IOException: Too many open files at…
mal
  • 3,022
  • 5
  • 32
  • 62
3
votes
1 answer

The receiveBufferSize not being honored. UDP packet truncated

netty 4.0.24 I am passing XML over UDP. When receiving the UPD packet, the packet is always of length 2048, truncating the message. Even though, I have attempted to set the receive buffer size to something larger (4096, 8192, 65536) but it is not…
Chris M
  • 31
  • 3
1
2
3
16 17