Category Archives: p300

Chat feature in p300

In case you are interested in testing the new messenger-feature in p300 drop me a e-mail :)

It is not very advanced compared to real messengers but for writing short messages it’s perfect.

Bandwidth limiting problems

Our beta tester ShadowIce found (and hopefully solved) some problems with the p300 bandwidth limiting code when you are using Windows 2000 and Opera. It made web browsing very slow when an upload was running and bandwidth limited in p300. This will be fixed in the next release.

Thanks ShadowIce!

p300 revision 685 released

The latest version of p300 mainly focuses on UI improvements and some smaller bugfixes under the hood.

Changes include:

  • polished the web ui a bit
  • getRandomChunk was returning 0 too often
  • started GUI changes to make p300 look more messenger-like
  • return 501 for DELETE, LOCK etc
  • changed “open webinterface” to a tree item
  • moved “copy my url” button to settings
  • more icons
  • search hosts directly from browser
  • version displayed in main window
  • sharemonkey link in search results
  • complete main window tree not collapsable anymore
  • fixed search bug when file index was not created yet
  • no more grid lines in JTables
  • better handling of the context menu in the file browser

Have fun :)

New p300 look

The new p300 version will have an updated look which is more messenger-like. Also I have done some usability improvements.

Contact me if you want to test :)

Window locations in Java

I’m currently changing the windows in p300 to a MDI interface.

While doing this, I have found a nice Java thing: setLocationByPlatform enables you to let your JVM choose the position of a new Window. This means that windows won’t be placed at 0,0 but will be overlapped according to what your platform thinks is nice.

p300 641 has been released

The latest version of p300 is a bugfix release, fixes and enhancements include:

  • Better usage of Selector
  • Global exception handler
  • Properly set application name on OS X
  • Check if we can really allocate a new file (does not work that properly yet)
  • Do not query ourselves when getting a hostname pointing to us
  • Only use ipv4 for the moment
  • Fail if DISPLAY environment variable is set but we cannot initialize the UI
  • Make sure we don’t save duplicate addresses for a host
  • Fixed move problem with downloading 0-bytes files
  • When 75% of incoming connection slots are in use we deactivate HTTP keep-aliv

Have fun :)

Catching Exceptions with an UncaughtExceptionHandler in Java

I’ve recently spent some hours to track down a mysterious bug and I just couldn’t find it. Since my application is using a lot of Threads/Workers  it came to my mind that a RuntimeException I did not catch could be the cause. I wrote a global handler for it and found where the problem was :)

The code in p300 I am using:

Somewhere in main():

Thread.setDefaultUncaughtExceptionHandler(new P300UncaughtExceptionHandler ());

The class:

public class P300UncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
    public void uncaughtException(Thread t, Throwable e) {
        System.err.println ("Uncaught exception by " + t + ":");

How to test it:

new Thread () { public void run () { throw new RuntimeException ("x");}}.start ();

Using a Selector in Java NIO

For p300 I am currently using a Selector to check if I can read from or write to a socket.

However this lead me to a weird problem: I am selecting for at most 30 seconds and I have received a timeout for writing even though this can’t really be and only happens with some OS combinations. I’ve found this thread in the Sun Forums and adapted my internal logic to the information from this thread:

Instead of always selecting for OP_WRITE when I want to write, I just try to write. If i was not able to write everything (that is, buffer.remaining () > 0) I select for OP_WRITE.

This seems to work fine :)

(That fix is not in p300 619 yet, it will come with the next bugfix release in the next days)

p300 Revision 619 released

I have released a new version of the p300 file sharing tool. Changes:

  • Better re-using of HTTP connections
  • Downloader UI updates more often
  • More efficient handling of Downloader-Threads
  • Manually discover other host improved
  • Manual adding of downloads
  • Opening of finished download directory directly from UI
  • When a download finishes, the waiting downloads will be re-started
  • Better selection of chunks to download
  • If a host has multiple IPs, use them also for directory downloads and not only for file downloads
  • Delete old download meta files
  • Show offline hosts in UI
  • Only move one download at a time
  • Fixed bug with setting bandwidth limit exceptions
  • Fix invalid chars in downloaded filenames
  • Leadbullet integration
  • Preallocate download file

Get it at the p300 website.

Thanks to the people who tested it :)

setSoTimeout of a Socket and Java NIO

A stupid thing about Java NIO and using blocking sockets (Who does that? Me in p300 because I want to use the increased performance of using FileChannel.transferFrom) is that the SO_TIMEOUT is not used anymore even if you set it.

However, switching to nonblocking IO is not that hard. You can use one Selector per SocketChannel and select() for OP_READ or OP_WRITE before every read or write. This way you can have a select (timeout in msec).

Shareaza Auto Updater

I have read that that the Updater of Shareaza will download another client that is not the original Shareaza but another Gnutella client, together with some Adware.

Even though p300 has a very very small userbase I am happy that I have implemented cryptographical signing from day 1. So such a thing will not happen if someone is able to get hold of the p300 website.

By the way, the real Shareaza page is on sourceforge now.

Java as native code

I consider checking out GCJ (with or without SwingWT) for the Windows-Version of one of the next p300 releases. But first I’d have to see which licensing issues this would bring up :)

Why only the Windows Version? OS X users can be happy to have Java per installed default, Linux users are used to installing things (in this case a JVM).

Revision 541 released

This is a rather boring new release with not much new features, but some bug fixes:

  • Properly allow network prefixes that are not class C on first start (java 1.6 only)
  • Charset fixes (thanks Sebastian)
  • Moved download directory setting to a new config page
  • Also use broadcast for discovery (this is optional)
  • Use a proxy if set and where applicable (auto updater for example)
  • Fixed bugs in the indexer (thanks Sebastian)
  • Changed locking in the downloader (if p300 locks up now please blame me :) )
  • Use less file open/close in the downloader
  • Improved logging

Get it from the p300 site :)

Implementing the Downloader (2)

(Part 1)

I had problems with moving files after their downloading has been finished. These problems did not occur on Unix-like operating systems like my OS X and Linux but only with Windows. I just was not able to move the file with file.renameTo of the Java API.

After some researching on the web and especially the Sun forums I saw that I am not alone with this problem. The solution is stupid but logical: Before using file.delete() or file.renameTo():

  • Of course, make sure to close the file :)
  • Call System.gc() and then System.runFinalization(). Sleep a second and run System.gc() again. This makes sure that the Sun Java VM really closes the file and frees resources associated with it.
  • For temporary files, also use file.deleteOnExit()