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

Send multiple files using Java NIO SocketChannel

I have tried sending files using java NIO socket channels according to this guide. It works fine. I modified the method to send List of files. Basically, i loop through the files list and call send method already implemented in the above-mentioned…
Arunwij
  • 390
  • 1
  • 4
  • 22
0
votes
0 answers

android output stream flush issue

I am developing one android application for server emulation(like Online terminal) using SocketChannel(Java Native) for stream connection. But in the application I am trying to flush the output stream every time after I send the data to the server.…
0
votes
0 answers

Issue using Selector to get a write timeout

I am trying to add a write timeout to a SocketChannel by using a Selector: public int write(ByteBuffer buf, long timeout, SocketChannel socketChannel, Selector selector) { int written = socketChannel.write(buf); if (written == 0) { …
Slin
  • 1
  • 3
0
votes
1 answer

HTTPS protocol server request upgrade Java socketchannels

So I am trying to build an HTTPS server in java without using SocketChannels and the SSLEngine. My main reason is when I built using the com.sun packaging and tested it a lot of request timed out and if they did respond they took around 2 minutes…
Moocow9m T
  • 45
  • 7
0
votes
1 answer

How to make a SocketChannel ready for read

According to https://docs.oracle.com/javase/7/docs/api/java/nio/channels/SelectionKey.html#OP_READ Suppose that a selection key's interest set contains OP_READ at the start of a selection operation. If the selector detects that the corresponding…
Ertai Duo
  • 11
  • 3
0
votes
1 answer

why does SocketChannel invoke read(byteBuffer) throw java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)

Our project implements ourself long-connection framework base on NIO for push, it used to work properly. Lately, there are some problem, "SocketChannel.read(byteBuffer)" throw exception "java.net.SocketException: recvfrom failed: ECONNRESET…
0
votes
1 answer

Java socketChannel to detect disorderly closed connection

I know that a SocketChannel is "notified" about an orderly closed connection by receiving "-1" after calling read(). But how can it notify me about an disorderly closed connection? (as part of a whole NIO based server, working with selector and…
slashms
  • 928
  • 9
  • 26
0
votes
0 answers

SOCKETCHANNEL exception

in my code i am monitoring a socket channels ,but once the code reach this server = ServerSocketChannel.open(); server.configureBlocking(false); server.socket().bind(new InetSocketAddress(IpAddress,…
0
votes
2 answers

Spark unable to create SparkContext

I am trying to create/get new/old SparkContext using this method private final val externalConfig = ConfigFactory.parseFile(new File("/mnt/extra.conf")) private final val conf = new SparkConf(true) .set("spark.cassandra.connection.host",…
H Raval
  • 1,903
  • 17
  • 39
0
votes
2 answers

java.lang.Object cannot be cast to java.nio.channels.SocketChannel

In my app i have this code: SamplePoolableObjectFactory factory = new SamplePoolableObjectFactory(); this.pool = new SampleObjectPool(factory); ..... SocketChannel channel = null; try { channel = (SocketChannel)…
Mercer
  • 9,736
  • 30
  • 105
  • 170
0
votes
2 answers

Is it possible to stub or mock a SocketChannel with Spock?

Essentially I have a Java class which performs a select on a socket channel, and I want to stub the channel such that I can test select works as expected. For example, this is roughly what the class being tested does: class TestedClass { …
wu-lee
  • 749
  • 4
  • 17
0
votes
2 answers

SocketChannel in Android

I have a question about SocketChannels in Android. This is my code: SocketChannel socketChannel = SocketChannel.open(); socketChannel.connect(new InetSocketAddress("127.0.0.1", 90)); This code works in Java but not in Android. I always get an…
Martin
  • 313
  • 1
  • 3
  • 12
0
votes
0 answers

java.nio.BufferOverflowException despite buffer.clear()

I am implementing a middleware between clients of the memaslapbenchmark and the memcachedserver. The key size is set to 16Bytes and the value size to 1024Bytes, so the request should never exceed 2048Bytes which is MAX_PACKET_LENGTH in the following…
Dr3w Br1ck13
  • 187
  • 1
  • 5
  • 14
0
votes
1 answer

ByteBuffer over SocketChannel

I am trying to get File moved over IP (SocketChannel) by starting to send the file name. The issue I believe is in the reading of the ByteBuffer but I am not sure how to correct it. FileSender Part: public void sendFile(SocketChannel…
user3025039
0
votes
0 answers

java.io.StreamCorruptedException: invalid stream header: 00000000 when reading from ObjectInputStream

I'm writing some networking code that writes basic packet constructs and sends them over a SocketChannel. I have the following relevant code: in IOPacket (abstract implementation of the Packet interface, main thing getting sent over the…
Evan Hall
  • 58
  • 1
  • 8