powered by Jive Software

Measure Traffic

Hello everyone,

for an application with Smack I would like to be able to measure the raw traffic that is being generated. So basically I want to count every byte Smack writes to a BufferedWriter on it’s connection and reads from the BufferedReader. I didn’t found anything usable in the JavaDocs. But probabilities are very high that I overlooked it Does anyone of you have a hint how I can do this the most elegant way?

Thanks in advance

Hi,

are you interested in the uncompressed data or the usually compressed and encrypted data which is sent over the wire?

LG

I’m interested in the amount of data which goes over the wire (or the wireless connection). In the field of my mobile applications it could be useful to know how mich included volume of your plan is being used by instant messaging.

try tcpdump or ethereal

I’d look into the debugger class and count chars there. This doesn’t work for compression though.

Otherwise you could try to patch smack to get a delegating stream at the lowest possible level, this would give quite accurate countings,

Keep in mind that data plans have a wired byte-counting.

[EDIT] Here is a way to do it unpatched:

private void connectUsingConfiguration(ConnectionConfiguration config) throws XMPPException {
        this.host = config.getHost();
        this.port = config.getPort();
        try {
            if (config.getSocketFactory() == null) {
                this.socket = new Socket(host, port);
            }
            else {
                this.socket = config.getSocketFactory().createSocket(host, port);
            }

So you can provide a SocketFactory with your own config. This enables you to highjack the Input/OutputStream below Smack.