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

What are the factors affecting the speed in sending large amount of data in SocketChannel?

Can someone tell me what are the specific factors affecting the speed in sending large amount of data in the SocketChannel? For example is the byte allocation affects the speed?
0
votes
0 answers

netty EpollServerSocketChannel SO_BACKLOG

I'm using netty 4.0.36-Final and I'm trying to set the SO_BACKLOG option on a channel. My simple goal is to have a server that refuse all the connections. In order to have this I thought that would have been enough setting AUTO_READ to false and…
0
votes
1 answer

Using Blocking NIO in Java

I'm just wondering if it is possible to use the SocketChannel class (with ByteBuffer) to simulate the blocking features of the regular Socket class in Java. I made two Test projects, one simulating the Client and the other simulating the…
0
votes
1 answer

Extend SocketChannel to add custom read and write

I'm trying to send serialized object over channels. The idea is to extend SocketChannel with method constructor that save Object to send, and add method writeObj() in order to send serialized object size followed by serialized object. Using private…
Alessandro
  • 199
  • 2
  • 16
0
votes
1 answer

Byte[] sent across SocketChannel but not received

I've been having some trouble with a project that requires a bit of networking, where data is sent over a SocketChannel but is never received. I was able to replicate the issue with a simple localhost chatroom program (sorry if it's a bit…
Evan Hall
  • 58
  • 1
  • 8
0
votes
1 answer

SocketChannel high CPU load on read

I have SocketChannel configured for read only SelectionKey.OP_CONNECT | SelectionKey.OP_READ Profiler shows runChannel is the most CPU consuming method and actually it is reasonable because it's infinite loop which calls method selector.select() all…
Diyko
  • 388
  • 1
  • 8
  • 28
0
votes
3 answers

Sending a jpeg image over a socketChannel

I'm currently testing out programming skills I'd need for a small game I'm planning to write eventually, and I'm currently stuck at transferring an image over a socket channel. I plan to test this on a "Battleship" program I wrote by sending some…
PixelMaster
  • 895
  • 10
  • 28
0
votes
1 answer

The difference of SocketChannel.read() in async and sync mode?

I know that java NIO have two modes , the asynchronized and synchronized mode.When I am reading the javadoc of SocketChannel.read(), I get the explaination below: Reads a sequence of bytes from this channel into the given buffer. An attempt is made…
wuchang
  • 3,003
  • 8
  • 42
  • 66
0
votes
1 answer

Primefaces Push Private Channel wrong room/user/user/user/

When I'm testing the primefaces(5.2) push example (counter, notify, photoshared) all work completely, except chat (same code from page primefaces, copy paste the code from example page), here occur a detail: username:"felipe" log in (private…
fperez
  • 482
  • 1
  • 5
  • 17
0
votes
1 answer

Android TCP client using socketchannel. How can I set options for it?

I am working on a client for an android device running on android version 4.4.2 and I have found some strange behavior from it. Most likely it is because it is waiting for more data before building a package, but I do not want that so i am trying to…
Noobs DeSroobs
  • 253
  • 1
  • 6
  • 24
0
votes
1 answer

Validating data received in a non blocking server

I am building a non blocking server using javas NIO package, and have a couple questions about validating received data. I have noticed that when i call read on a socket channel, it will attempt to fill the byte buffer that it is reading to (as per…
vimalloc
  • 3,869
  • 4
  • 32
  • 45
0
votes
1 answer

How to improve the performance of the following code using socketchannel? And how can I receive UTF8 string?

here is the important code: public void setSelector() { try { this.writebuf.clear(); this.selector = Selector.open(); int interestSet = SelectionKey.OP_READ | SelectionKey.OP_WRITE; SelectionKey selectionKey =…
Jan
  • 1
  • 2
0
votes
1 answer

Java nio SelectionKey.register and interestops

I have been working on Java NIO communications and reading various writeups regarding this. The document says that I could "or" ops that I am interested in. However, I haven't seen a single example…
Faraz
  • 5
  • 1
0
votes
1 answer

Further cleanup after closing a socket channel

Is there need to do further cleanup after closing a socket channel if the channel was used with a selector and the selector is still being used?
traveh
  • 2,700
  • 3
  • 27
  • 44
0
votes
0 answers

Java WindowsSelectorImpl totalChannels

server.register(selector, SelectionKey.OP_CONNECT); server.connect(address); Any idea why when I inspect selector in WindowsSelectorImpl I see totalChannels = 2 even though I register only one channel?
traveh
  • 2,700
  • 3
  • 27
  • 44