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

Java NIO: Read data from Channel which does not contain any data. How do I handle this situation?

Java code below: import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; public class Test { public static void main(String[] args) throws IOException { …
user471011
  • 7,104
  • 17
  • 69
  • 97
0
votes
2 answers

Java NIO. Why flip() method breaks my program?

Java code below: import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; public class Test { public static void main(String args[]) throws IOException { …
user471011
  • 7,104
  • 17
  • 69
  • 97
0
votes
1 answer

Java NIO ByteBuffer : read the message size on head before read the complete message

I'm making a java NIO server which receive messages, each message have its size on the head of the message, that why I'm reading first into a buffer which have default size(44), then get the complete size from this buffer, and then create a new…
Fozix
  • 133
  • 3
  • 12
0
votes
2 answers

Java SocketChannel read the messages of unknown length

SocketChannel channel = (SocketChannel) key.channel(); ByteBuffer buffer = ByteBuffer.allocate(1024); int numRead = -1; try { numRead = channel.read(buffer); System.out.println("numRead: " + numRead); } catch…
user1221483
  • 431
  • 2
  • 7
  • 20
0
votes
1 answer

ConcurrentHashMap not inserting the non null key value pair upon calling the put method

I am using a ConcurrentHashMap to cache task that I am processing on a SocketChannel. The StreamTask is a Runnable that is use to reschedules itself if the round trip threshold is elapse during client server communication, therefore it will remove…
Robert Brooks
  • 701
  • 2
  • 8
  • 12
0
votes
1 answer

how to tell whether a connection is established in java?

I tried to build a socket channel between two emulators in android. I wrote the following code: public SocketChannel connect2node(String ip, int port) { SocketChannel client = null; try { client =…
stackunderflow
  • 877
  • 4
  • 13
  • 28
-1
votes
2 answers

Selector.select() is not blocking after a SelectionKey.isReadable is read

I have a Socket that connects to a ServerSocketChannel which passes off to another Selector. The client socket sends a one time message of 8 bytes, I successfully read it, but then selector which I call selectorIO should block on the select()…
Matthew
  • 3,886
  • 7
  • 47
  • 84
-1
votes
1 answer

SocketChannel.write() throwing OutOfMemoryError when attempting to write large buffer

My code throws an OutOfMemoryError when running the following line: int numBytes = socketChannel.write(_send_buffer); where socketChannel is an instance of java.nio.channels.SocketChannel and _send_buffer is an instance of java.nio.ByteBuffer The…
topher217
  • 1,188
  • 12
  • 35
-1
votes
1 answer

How to read more than 1024 bytes to x bytes in Netty

I am new here. I have this issue with netty. Data is getting truncated when it exceeds 1024 bytes. this issue arose when i ported from norm io Socket to Netty, using io i can read any data of x bytes like this TheClient is a separate thread that…
milo7
  • 1
  • 1
-1
votes
1 answer

ServerSocketChannel.socket() is still bound after close()

I Used java.nio for server programming and it works fine. When I try to close socket: serverChannel.socket().close(); serverChannel.close(); boolean b1 = serverChannel.socket().isBound(); boolean b2 = …
GauravRatnawat
  • 717
  • 1
  • 11
  • 25
-1
votes
2 answers

Paramiko channel send request to start trace remotely

I am new to this concept so please help! I am using Paramiko Channel to execute a command and start a trace. I want the trace to continue running until I send a stop request to trace. If I use channel.send(cmd) it starts and stops the trace whereas…
-1
votes
1 answer

How do you transfer a socket connection from one socketchannel to another?

I have a ServerSocketChannel and once this channel accepts a connection I want to "transfer" or "pass" it to a SocketChannel. I have tried, once I have accepted the connection, to simply do a…
-1
votes
1 answer

Java NIO Socketchannel only sends data after shutting down output. Why is this?

I am trying to write a program which accepts java nio SocketChannel Connections but also keeps them open. So lets say the Client sends a message, then should the Server immediately send the same message back (Simple Echo Server), but the answering…
user10170559
-1
votes
1 answer

Java NIO Socket Channel mismatch in size of sent and received bytes

I have the server and the client. Server sends data using this: private int writeMessage(AgentHandler agentHandler, Msg message) { SocketChannel sc = agentHandler.getSocketChannel(); byte[] encodedMessage =…
-1
votes
2 answers

SocketChannelImpl.write(ByteBuffer[] srcs, int offset, int length) appends ByteBuffer of size 0

I have a client-server application communicating over Java NIO sockets which makes use of the SocketChannelImpl class underneath. When from the senders side, I send a ByteBuffer array of length n elements, the client always receives ByteBuffer array…
jaywalker
  • 1,116
  • 4
  • 26
  • 44
1 2 3
16
17