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

Java non-Blocking SocketChannel not receiving after certain size

My code is structured into three classes Coordinator, Sender and Receiver. Coordinator takes a size from user and informs sender about it sender. Then sender first tells this size to receiver and then sends that much data to receiver. Once receiver…
PHcoDer
  • 1,166
  • 10
  • 23
2
votes
0 answers

Java SocketChannel.bind() binding to 127.0.1.1, even if passed machines public name

I am using following code to bind a SocketChannel to a port. private ServerSocketChannel channel; channel = ServerSocketChannel.open(); channel.bind(new…
PHcoDer
  • 1,166
  • 10
  • 23
2
votes
2 answers

Reliable write to Java SocketChannel

I'd have a question regarding java SocketChannel. Say I have a socket channel opened in blocking mode; after calling the the write(ByteBuffer) method, I get an integer describing how many bytes were written. The javadoc says: "Returns: The number of…
2
votes
2 answers

Flow control on blocking queue and SocketChannel write

I have a blocking queue where multiple writers are writing. I want to put a transaction control mechanism where not more than, say, 50 writers(or near) can write per second. Is there a way I can achieve it? Edit 1: There is a similar requirement to…
Abhash Upadhyaya
  • 717
  • 14
  • 34
2
votes
1 answer

NIO chat application not working properly for multiple clients

I've been working on a NIO-based chat application of quite trivial logic: any message sent by any client should be visible to the rest of the users. Right now, I'm sort of in the middle of the work, I've got pretty complete classes of the clients…
musztard2000
  • 127
  • 2
  • 14
2
votes
1 answer

SocketChannel and FileChannel.transferFrom/To

I just learnt about the java nio package and channels and now, I tried to write a really simple file transfer program using channels. My aim was to get rid of all this bytewise reading stuff. As a first try, I wrote the following server code:…
Green绿色
  • 1,620
  • 1
  • 16
  • 43
2
votes
1 answer

Using 1 SocketChannel for 2-way "real-time communictation"

I'm receiving a continuous stream of data that I'm saving to a ByteBuffer. Sometimes I need to write to the channel, however, it's important not to lose any data. Is it possible to use the selector to solve this issue? If I'm constantly checking…
Jan Beneš
  • 742
  • 1
  • 5
  • 24
2
votes
3 answers

Using an SSLContext to create a SocketChannel

I'm looking to implement NIO for a SSL socket. However, every example that I've found, uses SocketChannel.open() to get the socket channel. From a SSLContext, how can I get a SocketChannel?
judepereira
  • 1,239
  • 2
  • 17
  • 24
2
votes
1 answer

Read on SocketChannel reaches end-of-stream after ServerSocketChannel performs accept

I've pasted a server side code snippet below. This server code works under normal circumstances, however, the following scenario manages to break the code. Server and client are on the same machine. I used the loopback address, and the actual IP…
mike
  • 4,929
  • 4
  • 40
  • 80
2
votes
2 answers

HttpPost: InputDispatcher: "Channel is unrecoverably broken and will be disposed!" on Nexus 7

On Nexus 7 (4.3), and not on my older device, LG Optimus 3d (Android 2.2), when I do HttpPost, I get this E/InputDispatcher﹕ channel '4273f7b0 ... MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed! People have mentioned…
mylord
  • 699
  • 2
  • 12
  • 20
2
votes
0 answers

Using resources of try-with-resources outside try

I'm using SocketChannel to send message between a server and a client. Once a client connects with a server, the server opens the InputStreams and OutputStream in a try-with-resources try, to receive messages from the client and send messages to the…
2
votes
1 answer

Connecting to websocket using SocketChannel Android

I have written android app which connects to a websocket server, server app and android app implemented with Autobahn websocket library. I can connect and exchange the messages with server successfully. but after some time(after 20 - 30 mins) …
eranga
  • 519
  • 7
  • 17
2
votes
0 answers

msgpack-java & java.nio.SocketChannel

I'm having a hard time figuring out how to setup a non-blocking IO (network sockets) using msgpack. The write portion is trivial since msgpack can generate a ByteBuffer fairly easily, but I can't figure out how to do non-blocking read into the…
ruckc
  • 505
  • 1
  • 6
  • 23
2
votes
2 answers

Java SocketChannel : Why wrap-flip-write doesn't work but wrap-write does?

Assume we have a Java SocketChannel connected to a server which is waiting for incoming data: SocketChannel server = SocketChannel.open(); server.connect(new InetSocketAddress(ip, port)); And we send our request as below: byte[] request = "This is…
Seyed Mohammad
  • 798
  • 10
  • 29
2
votes
1 answer

Java NIO read() End Of Stream

I'm using Java NIO in to accept, read and write in my server. In the documentation it said that the SocketChannel.read() function will return the number of bytes read from socket, and -1 if it reach end of stream. Now - i don't really understand…
Asaf Nevo
  • 11,338
  • 23
  • 79
  • 154