James Kirk

Greenhorn
+ Follow
since Dec 12, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by James Kirk

Stephan van Hulst wrote:Well, I haven't really used memory mapped I/O so far, so I can't be sure, but maybe some of the methods of MappedByteBuffer can help you out.

If not, and this type of performance is really what you want, maybe it's best to write native code that handles IPC, and then use JNA to invoke these native methods.



The method I mentioned above creates the MappedByteBuffer. A MappedByteBuffer alone can not be used for IPC, thus the well known workaround to map a shared file.

Cheers,
JK
12 years ago
Hi all,
I need to pass masses of data between two processes. Apart from sockets etc, using mmap is a standard approach for native programmes. Java FileChannel supports map, but there it reads:
"Read/write: Changes made to the resulting buffer will eventually be propagated to the file; they may or may not be made visible to other programs that have mapped the same file."
http://docs.oracle.com/javase/7/docs/api/java/nio/channels/FileChannel.html#map(java.nio.channels.FileChannel.MapMode,%20long,%20long)

So the FileChannel#map is not guaranteed to work for IPC? Has someone here successfully used it anyway?

Many TIA,
-- JK
12 years ago

Stephan van Hulst wrote:Yes, but he wants to detect failing peers, not peers that are finished with what they're doing.

James, there is no way you can do this in Java. You could write complex native code that checks whether you received TCP ACKs, if that is even possible, but it wouldn't be worth it.

Maybe what you can do is have some sort of heartbeat. At intervals send a message to a client and the client has to respond within a certain amount of time. This of course is not an elegant solution. And if your application already sends data regularly, sending an application level acknowledgment is roughly equivalent.

So you need to figure out for yourself whether you want to do these acknowledgments or not. You can still detect whether clients have dropped if you send data regularly, and the connection will just fail after a while. This should be good enough for statistics. If you want more security than that, you will have to use an ack mechanism.



Thanks for your suggestion. This is my wore case solution, because I want to avoid any extra traffic.
12 years ago

Stephan van Hulst wrote:Hi James, welcome to CodeRanch!

I don't think you can. Is there a reason you want to do this anyway?



Yes of course. I need to detect failing peers. As I regularly send data to them anyway, I would like to use this communication to ensure the receiver actually is still there. It basically works, but you have to send big enough data so all the involved buffers get flushed. I want to avoid a scenario where I have to send a confirmation back if the message is small.

Cheers,
JK
12 years ago

Campbell Ritchie wrote:Don’t know myself, but welcome to the Ranch



Thanks a lot!

I have been searching for a good Java forum quite a while. Now I finally found one (-:
12 years ago
Hi there,
I am writing to a socketchannel whose receiving peer may disconnect in between writes. The problem now is, I can still write small amouts* of data to the channel without an error, even if the receiving side is not connected anymore. So my question is: can I safely detect if a connection has been dropped without an extra acknowledge mechanism?

This old post seems to be related: https://coderanch.com/t/552684/java/java/Java-NIO-socket-communication-why

* this may be related to the size of the socket send buffer

Many TIA,
JK
12 years ago
Hi there,
I am digging out a rather old post, but it perfectly describes my question. My problem with the above setup is: The sending side only seems to recognize the dropped connection, if I send more data than I actually intend to (probably one has to send more than fits in the sockets send buffer). So my question is: can I safely detect if a connection has been dropped without an extra acknowledge mechanism?

Many TIA,
-- JK
12 years ago