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

java.nio.channels.SocketChannel for both periodic write and immediate read

I want to write a client application which send messages to server and receive its reply. The client sends messages many times (for example one message in very second periodically) regardless of replies. When a reply comes back, the client want to…
1
vote
3 answers

java: Single socket on read write operation. Full duplex

I have to implement sending data with specific source port and in the same time listen to that port. Full duplex. Does anybody know how to implement it on java. I tried to create separate thread for listening on socket input stream but it doesnt…
Diyko
  • 388
  • 1
  • 8
  • 28
1
vote
1 answer

AsynchronousServerSocketChannel finally block never executed

I create AsynchronousServerSocketChannel and everything is fine untill I want close server socket socket. I create AsynchronousSocketChannel on client with special message which call function to close server and all socket channels, server is closed…
user2803095
  • 347
  • 1
  • 4
  • 16
1
vote
1 answer

Distinguish between messages sent from CLIENT and other

I am using SocketChannel and Selector to write a server. The servers job is to allow clients to connect, read messages from clients and write messages to clients. I am having some difficulty distinguishing between messages sent from the client, and…
Ian2thedv
  • 2,691
  • 2
  • 26
  • 47
1
vote
1 answer

Simple Client-Server Program with NIO channels

SOLVED If anyone would be interested I could edit this post with correct data. Just leave a comment. As my assignment I had to create a simple server and a client using non-blocking channels and selectors. Basically it should either echo the…
justMe
  • 674
  • 7
  • 26
1
vote
1 answer

SocketChannel write( ) returns with no error but no data was actually sent

I am using SocketChannel to communicate with remote server. I send data using socketChannel.write() with no errors and exceptions, however, the server log indicates no data was received; client tcp traffic monitor also shows that the string message…
wizoleliam
  • 83
  • 3
  • 13
1
vote
1 answer

How to make sure the SocketChannel is really connected when using NIO?

I'm working on a NIO client program on Android, Basically it functions well, but when the network is not avaliable(WIFI is disabled, etc), I have no idea how to distinguish the socket is 'really' connected, SocketChannel.finishConnect() always…
Paparika
  • 137
  • 1
  • 12
1
vote
1 answer

when socketChannel.read(BUFFER) will return 0

I have a server which reads from the SocketChannel like below: private void readDataFromSocket(SocketChannel socketChannel) throws IOException { BUFFER.clear(); int count = 0; while ((count =…
Trying
  • 14,004
  • 9
  • 70
  • 110
1
vote
2 answers

Any issues with replacing new Socket() with SocketChannel.open().socket()?

What can go wrong if I simply replace socket = new Socket() with socket = SocketChannel.open().socket()? Background: I have some legacy code using new Socket(), and I wanted to be able to interrupt the socket.connect() call. I don't want to…
Robert Tupelo-Schneck
  • 10,047
  • 4
  • 47
  • 58
1
vote
2 answers

How to find and cancel idle channels of a selector?

Let's say we have a Java NIO Selector that selects with a timeout on multiple SocketChannels for read operations: Selector selector = Selector.open(); channel1.register(selector, SelectionKey.OP_READ); channel2.register(selector,…
Seyed Mohammad
  • 798
  • 10
  • 29
1
vote
1 answer

Netty 4 ReadTimeoutHandler not throwing in OioEventLoopGroup

I'm new to netty. Is this an expected behaviour? A bit more detailed: public class Test { public static void connect(){ EventLoopGroup workerGroup = new NioEventLoopGroup(); Bootstrap bs = new Bootstrap(); bs.group(workerGroup); …
grigory.t.
  • 15
  • 4
1
vote
2 answers

Java SocketChannel Eating my bytes

I created a SocketChannel to a remote server to send and receive messages on Tomcat. To receive messages from a remote computer, I used a thread dedicated to task (only this thread will read from the socket, nothing else). When some bytes are…
futureelite7
  • 11,462
  • 10
  • 53
  • 87
1
vote
1 answer

how to switch blocking mode of socketchannel?

I use SocketChannel to receive TCP stream from server on client side. For example: Selector selector=Selector.open(); SocketChannel mychannel=SocketChannel.open(new InetSocketAddress(ip,port)); channel.configureBlocking(false); SelectionKey…
William
  • 45
  • 1
  • 2
  • 9
1
vote
3 answers

Java nio read() return -1

it's not my first time trying to understand this issue but i hope it will be the last one: some background: i have a Java SocketChannel NIO server working in non-blocking mode. this server has multiple clients which send and receive messages from…
Asaf Nevo
  • 11,338
  • 23
  • 79
  • 154
1
vote
0 answers

Android client app talk to normal multiple thread server using socketChannel

I have a android JAVA application which talk to third party server with normal TCP serversocket(multiple threading), Will it work if I use socketChannel client in the android app? the app used to be using socket client, if it is running normal…
Seck Ghost
  • 43
  • 2