File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes suggestions needed for data transfers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "suggestions needed for data transfers" Watch "suggestions needed for data transfers" New topic

suggestions needed for data transfers

Chris Shepherd
Ranch Hand

Joined: Jun 27, 2000
Posts: 286
First off, if this is the wrong forum for this, please move it... I wasn't sure where this would fit in so I decided to put it here. On to business.
I have been using java to build standalone apps for 3 years, but I have never writen any java apps for running over the network/internet and now I need to. I have a java program that collects data from custom hardware through JNI. I want to be able to distribute packets of information out to "registered" java clients that are connected via the network/internet. This data could be anywhere between 50 bytes to 10k bytes per message. I would like to be able to send out 2 packets/second/client if possible. I also need to be able to accept requests for specific data from the clients.
I have a slightly older book on java networking, but I didn't know if there was newer stuff that has been added in java 1.4 that might make this process easier. If anyone has had experience doing this type of thing and can give me some pointers/suggestions, I would really appreciate it.
[ February 21, 2003: Message edited by: Chris Shepherd ]
Jon Strayer
Ranch Hand

Joined: Dec 04, 2002
Posts: 133
Check out the NIO package. It's designed to make it easier to create servers.
I don't know how many clients you need to support, but it won't take too many 10KB packets to saturate a network.

Chris Shepherd
Ranch Hand

Joined: Jun 27, 2000
Posts: 286
Thanks for the suggestion. I will check it out. There probably wont be more than 2 or 3 clients in nearly all cases. That 10KB is about a maximum. Most packets should be closer to 500 bytes or less.
Any one else have any suggestions?
Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
In other words, the volume is low enough that there's no reason to use java.nio.* for performance reasons. In that case you'd just use the API you're most comfortable with.
  • Since this seems to be an all-Java environment, consider RMI. This will allow you to forget all about the networking and just model your updates and information requests as Java method calls.
  • If you don't want to use RMI, your next option would be sockets. This will be perfectly serviceable with the kind of volume you seem to be talking about. As establishing 10 or so TCP/IP connections a second, while not impossible, imposes rather more overhead than necessary, you would probably keep an open connection to each clients.
  • Do you need to be sure that your packets arrive at the client, or is it OK if you lose the odd packet? If you don't want to use RMI and your transport can be lossy, you could use UDP (Datagrams) instead of sockets.
  • This is probably not relevant to you, but if you need to distribute updates to a large number of clients and the odd packet loss is acceptable, you might be able to use multicasting. This will only work well on a fairly small, closed network, and certainly won't work over the internet.
  • My first choice would probably be RMI, with plain old (Server)Sockets as a second choice.
    By the way, this topic would be ideal for the Sockets and Internet Protocols forum.
    - Peter
    I agree. Here's the link:
    subject: suggestions needed for data transfers
    It's not a secret anymore!