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

Use HTTP or Socket from Android

I have to send data from Android phone to a server very frequently say every 100ms.(battery is not an issue). I am debating with myself whether it is OK to use the standard Java URL connection for this purpose or to create my own custom socket…
everydayapps
  • 455
  • 1
  • 5
  • 20
3
votes
1 answer

Setting timeout on blocking I/O ops with ServerSocketChannel doesn't work as expected

I'm working on a small group conversation server in Java and I'm currently hacking network code, but it seems like I cannot set right timeout on blocking I/O ops: chances are I've been bitten by some Java weirdness (or, simply, I misinterpret…
Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80
3
votes
2 answers

Java overhead with threads. Should I use sockets or socketchannels?

I have two designs for an instant message program that I'm writting in Java The first idea uses 2 separate threads. The first thread overlooks the gui and sends out the instant message data through writing to a blocking socket. The 2nd thread uses…
Dr.Knowitall
  • 10,080
  • 23
  • 82
  • 133
3
votes
1 answer

Java SocketChannel register() for multiple OP codes is never selected

I've built a Selector-based system in Java that can accept multiple clients. It has a ServerSocketChannel registered under OP_ACCEPT, which accept()s the incoming connection and registers the resulting SocketChannel with the selector again. Here's…
mtrc
  • 1,317
  • 3
  • 16
  • 39
2
votes
2 answers

How to communicate between non-blocking client and non-blocking server through only one SocketChannel

I'm trying to write a non-blocking client and non-blocking server with requirements: Server just listens to clients and send back to them what it has received Client can send message to server at anytime and can do it many times, but by just only…
Leo
  • 1,433
  • 23
  • 40
2
votes
2 answers

socketchannel.write() becomes very slow when message size is large

In my program using java nio, the socketchannel.write() becomes very slow when it tries to write 10 KB messages consecutively. The measured time for writing a complete 10 KB message is between 160 ms and 200 ms. But the time for writing a complete 5…
susan
  • 27
  • 1
  • 8
2
votes
0 answers

zero-copy from SocketChannel to SocketChannel

With Java's NIO API, is it possible to implement a zero-copy data transfer from one socket to another? I'm aware of FileChannel::transferTo() which does this from file to socket, but there isn't a transferTo() method on SocketChannel.
Gunnar
  • 18,095
  • 1
  • 53
  • 73
2
votes
1 answer

SocketChannel. invalid stream header: 00000000

I want to serialize 'Message' object, I can successfully transfer it as bytes array through socketChannel. After that, I change the object's properties (so that it may have larger size), and then there's a problem in sending object back to the…
Alxa
  • 79
  • 1
  • 2
  • 11
2
votes
1 answer

ConscryptEngine data read issue : Unable to parse TLS packet header

Below i the code for unwrap the data packets received from sslengine : private ByteBuffer doUnwrap() throws IOException { if (mPeerNetData.position() == 0) { // The network input buffer is empty; read data from the channel before…
Ashok Kumar
  • 1,226
  • 1
  • 10
  • 14
2
votes
0 answers

Netty Direct Buffer to SocketChannel.writerAndFlush()

I am new to Netty and I am trying to write a client functionality, to send dynamic messages using direct buffer. Below is code snippet I am currently using, is byteBuf.copy() "channel.writeAndFlush(byteBuf.copy())" the correct way of passing the…
Shankar
  • 21
  • 2
2
votes
0 answers

Closing a SocketChannel while doing a non-blocking read or write

Are there any potential risks associated with closing a socket channel from another thread while it is performing continuous non-blocking read or write operations. Would I need to synchronize on the channnel object? Thanks.
2
votes
2 answers

Do SocketChannel's have to be explicitly closed on the application shutdown?

Say we have an opened SocketChannel. Is it important to explicitly close it before terminating an application? In other words, if we don't do that, is any risk of leaving unclosed system resources?
Andremoniy
  • 34,031
  • 20
  • 135
  • 241
2
votes
1 answer

One thread stopping too early regardless of CyclicBarrier

I am aware of the fact that the following code may seem vulgar, but I am new to these things and just tried everything in order to get it to work.. Problem: Even though I am using (possible in a wrong way) a CyclicBarrier, one - and seems to always…
treiman
  • 59
  • 1
  • 6
2
votes
1 answer

What is the right thing to do if a socketChannel.close() got IOException?

I have a class that wraps socketChannel and has a close() method as follows: public void close() { // ... logic ... try { socketChannel.close(); } catch (IOException e) { // ??? } this.isConnected = false; } I…
slashms
  • 928
  • 9
  • 26
2
votes
1 answer

Java NIO Server/Client Chat App - sending data only by closing the socket

friends! I'm new to Java NIO and I'm currently trying to make a non-blocking chat app. The client connects to the server without problem. The client writes a message or few messages to the server but the server starts reading the messages only when…
bulibas
  • 27
  • 1
  • 4
1 2
3
16 17