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
83
votes
3 answers

Socket vs SocketChannel

I am trying to understand SocketChannels, and NIO in general. I know how to work with regular sockets and how to make a simple thread-per-client server (using the regular blocking sockets). So my questions: What is a SocketChannel? What is the…
Ramzi Khahil
  • 4,932
  • 4
  • 35
  • 69
19
votes
7 answers

Java NIO: transferFrom until end of stream

I'm playing around with the NIO library. I'm attempting to listen for a connection on port 8888 and once a connection is accepted, dump everything from that channel to somefile. I know how to do it with ByteBuffers, but I'd like to get it working…
aioobe
  • 413,195
  • 112
  • 811
  • 826
17
votes
3 answers

Timeout for SocketChannel doesn't work

I want to use a SocketChannel and to have a timeout for its read/write methods. I've tried to set a timeout for the Socket that owns my SocketChannel like this: channel.socket().setSoTimeout(TIMEOUT); but that doesn't work. Is there any other…
user345171
  • 171
  • 1
  • 1
  • 3
15
votes
3 answers

Java.nio Channels and TLS

How do I secure a Java SocketChannel, ServerSocketChannel or, perhaps even, a DatagramChannel with TLS? I know that there are some frameworks (#1 #2) that advertise to be able, but I want to know if it is possible to achieve this with the pure Java…
XZS
  • 2,374
  • 2
  • 19
  • 38
13
votes
4 answers

SSL and SocketChannel

Ideally, I only need a simple SSLSocketChannel. I already have a component that reads and writes message over ordinary SocketChannel, but for some of these connections, I have to use SSL over the wire; the operations over these connections,…
akappa
  • 10,220
  • 3
  • 39
  • 56
12
votes
2 answers

How to implement NIO Socket (client) using Kotlin coroutines in Java Code?

I want to use Kotlin(v1.3.0) coroutines & java.nio.channels.SocketChannel (NIO) to replace Socket connect (blocking IO) in Android. because this can save many number of threads. The code below can't run because of job.await() is suspending function…
haha
  • 121
  • 1
  • 1
  • 4
10
votes
2 answers

Is there a way to de-register a selector on a socket channel

This is a pretty straight forward question, but I have found a need to unregister a selector overlooking my socket channel for java. SocketChannel client = myServer.accept(); //forks off another client socket client.configureBlocking(false);//this…
Dr.Knowitall
  • 10,080
  • 23
  • 82
  • 133
8
votes
3 answers

Java SocketChannel doesn't detect disconnection?

I have a socket running, using selectors. I am trying to check to see if my socket is connected to the server or not. Boolean connected = _channel.isConnected(); and it always returns true. I turned off Airport (internet connection) on my computer,…
aryaxt
  • 76,198
  • 92
  • 293
  • 442
6
votes
4 answers

Java NIO: How to know when SocketChannel read() is complete with non-blocking I/O

I am currently using a non-blocking SocketChannel (Java 1.6) to act as a client to a Redis server. Redis accepts plain-text commands directly over a socket, terminated by CRLF and responds in-like, a quick example: SEND: 'PING\r\n' RECV:…
Riyad Kalla
  • 10,604
  • 7
  • 53
  • 56
5
votes
1 answer

Java ServerSocketChannel SocketChannel (Callback)

I am trying to learn Java. I would like to implement a simple networked connect 4 game as well as a chat feature. I want my network logic to be non blocking so after much study I found that SocketChannel is what I am after regrading my needs. What…
iTEgg
  • 8,212
  • 20
  • 73
  • 107
5
votes
2 answers

Connection was forcibly closed by the remote host

I have a java.nio.channels.SocketChannel in my jSCSI implamantation that is disconnecting when I try to open a driver with size greater than 4GB. The iscsi RFC says that the BasicHeaderSegment.BHS_FIXED_SIZE may be 48, so with this position I can…
Felipe Gutierrez
  • 525
  • 1
  • 9
  • 20
5
votes
2 answers

Read timeout for an NIO SocketChannel?

What is the best way to set a timeout to close a NIO SocketChannel if there is no data is received for a certain period after the connection is established?
Sam
  • 99
  • 1
  • 2
  • 8
5
votes
2 answers

Does SocketChannel.close() close the socket also?

I have a server program that needs to close any connections that remain when the server is shutting down. I know I need to call SocketChannel.close(). My question is if I also need to close the Socket associated with the SocketChannel or if…
4
votes
2 answers

Java Selector returns SelectionKey with OP_READ without data in infinity loop after writing to channel

I've trouble with my code: i've written simple SocketChannel client with Selector, after starting it successfully reads messages from server (server sends events). But after writing to socket (see main method) selector starts returning readable…
befire
  • 140
  • 1
  • 6
4
votes
0 answers

What are the rails best practices for structuring actioncable channels?

I am creating a trello clone, and want to integrate action cable. I have a main board view that multiple people can be added to. I want to establish a websocket connection for live updates. How should I structure my actioncable channels? Should…
I_A
  • 331
  • 2
  • 14
1
2 3
16 17