Using java.net.NetworkInterface I am getting the status (up/down) of network.
I want to get the value of send and receive byte on the network card.
And I need to calculate network utilization also.
How to get these in Java?
I don't think there is a pure Java way of doing this.
So one solution is to use JNI and a native library, which of course would have to be OS-specific.
If you want something more portable, I suggest trying out SNMP. All common OS should support querying such data via SNMP (perhaps after installing an SNMP server), and there are also Java SNMP client implementations available.
I would suggest using OSHI. The NetworkIF class supports everything you need.
Related
Please note: Although the library I'm using is called the Java Simple Serial Connector, this question is really more about Java coding against serial ports in general, and any strategies associated with doing so.
I'm using a Java library (JSSC as mentioned above) to read data from a serial port. The library requires you to poll the port for all available bytes. But this has me worried, because in between 2 different poll attempts, data could be streamed to the port (from the serial device) and therefore perhaps "lost".
Unless there is some kind of buffering/caching mechanism at the hardware layer that buffers data coming in to the serial port. In that case, the library's API makes sense, as it probably consults the buffer and reads anything thats been queueing up inside it. So I ask:
Is there such a "serial port buffer"? If so what is it? If not, then are there any strategies to "lossless" serial port reads?
If there is such a buffer, how does it work? What happens when it fills up?
The Java lib I'm using reads serial port data as byte[]'s; does it make sense to then construct a ByteArrayInputStream from these byte[]? What benefits would one gain from doing so?
I have coded a server in Java that will have several clients connected to it. I want to be able to see how much data is sent to each client to be able to make decisions like allowing more clients or decreasing them, or even to increase/decrease the frequency at which the data is sent.
How can I do that?
I'm currently using Java's Socket API, but if any other library gives me this easily, then a change can be done. The server will run in a linux flavor, likely Ubuntu, so a OS specific answer is welcomed too.
When you write data to the socket, you need to remember how much you sent. There really isn't smarter way to do this.
Generally speaking, you would allow the server to have a limited number of connections. Trying to tune the system based on bandwidth restrictions is very hard to get right.
I have a Java swing application that can uploads files to a server. It uses all the available upload bandwidth and that's okay when I'm at home. But it uses up a massive amount of upload bandwidth when I'm at work and so I wish to have some setting to limit bandwidth usage. How do I do it?
It's a multithreaded application so overriding the read method and adding extra logic would make the code more complex.
Is there a simple JVM setting for that? Or is there some java method like SomeJREClass.setMaximumAllowedBandwidth(int);
?
Thanks in advance
There is an open source library token-bucket which implements token bucket algorithm in Java. Maybe it can solve your problem.
I am working on a project where I need to convert bursts of data (in the range of 300 bytes) from Iridium's short burst data service . This is meant to replace a dial-up connection, so I need to take those bursts of data from the short bursts and convert them into the continuous stream of a dial-up connection.
I'm a relatively inexperienced programmer, and the only language I know is java.
How could I go about converting the data? Are there any background materials on how types of information packets operate and how to manipulate them in java?
[Edited for clarity]
EDIT2: I do not need to convert the data the other way around (from the stream to the chunks)
Your question is not clear on whether you are writing software to talk to the Iridium transceiver, or whether you are on the server-side, but I will assume you are on the client side since, judging by their website the server side is standard IP networking.
The program talks to the transceiver using an RS-232 interface and the AT (modem) command set. Using Java you will need some sort of serial library; I have had extensive experience with such, in particular with a program to manage a bank of modems bridging their comms to an IP network and at that time the only comms package which worked and was stable was SerialPort from SerialIO. The other potentially viable option is RxTx but when I worked with that several years ago it was unstable and would crash the JVM every few days. With either one you can (and should) constrain yourself to the JavaComm API which will enable you to easily switch out serial libraries.
Once you are talking to your serial port manipulating the transceiver should be the same as manipulating a modem, you will need to refer to the doco for specifics. If it's faithful to a modem, it will operate it two modes, command and data. In command mode you are sending AT xxx commands terminated by CRLF. When you are in data mode you are sending binary data.
The structure of the binary data will almost surely be dictated by the Iridium system, and you will need to conform to that; again see their doco.
If you have the luxury of defining your own data protocol, or if you have free-form messages atop their protocol my best advice is to make your messages logically keyword/value pairs to ensure long-term flexibility. If you are tight on space (and it seems like the size restrictions for Iridiums devices are fairly severe) you could make your keywords predefined (agreed on by client and server) and send a binary integer instead of, say a UTF-8 or ASCII string. The protocol should include or infer a very basic type so that numeric values, especially, can be as condensed as possible.
Anyway, I hope that gives you some direction and ideas of what to expect... please feel free to ask questions via comments, especially for particular questions about using a serial port from Java.
Can anyone tell me how to get network statistics using Java? Or how to measure network performance with simple time related metrics?
Thanks a lot!
It depends what do you mean.
If you want to measure network speed when downloading or uploading something you can create network connection, send some garbage and measure how long does it take to send. Better results can be achieved if both server and client sides are under your control.
But you can even write simple client that downloads file from external URL and measure how long does it take.
If you wish to know measure network parameters of other applications I recommend you to read about JPcap.
If you are looking for Bandwidth monitoring using Java, check the link below.
http://docstore.mik.ua/orelly/java-ent/dist/ch08_04.htm