[jcifs] JCIFS Over the internet..

Patrick Cerri robogiant at hotmail.com
Mon Oct 2 10:12:35 GMT 2006

Hi Mike & all concerned,

Have been using the most excellent JCIFS to create a java webstart file explorer for our company, that connects to an online Samba drive. Wanted to mention a few things I have found on my journey. 

I am using the library on my Win XP SP2 / Fedora Core 5 desktop over the internet, connecting to a Linux Box Fedora 3, with 2.6 kernel. Samba inbuilt.  I am compiling using the latest 1.5_07 jdk with netbeans. I have searched the mailing archives for answers to my questions, and I may just be using the library wrong. Hope not..

1) In SmbTransport.java, line 285..

        tconHostName = address.getHostName();

This can sometimes take up to 6 seconds to return!! I connect using an IP, not a domain name. Since speed is important in my app, I have changed it to

        tconHostName = address.getHostAddress(); 

seems to work now...

2) In SMBTransport.java line 230.. when creating a socket which binds to a local port

    socket = new Socket( thost, port, localAddr, localPort );

I have found that on some machines a Valid Local IP address is not found and only is available. Socket creation then fails as you can't bind to

I have tried to fix this by setting the jcifs property 'jcifs.smb.client.laddr' using the following code..

            boolean cont = true;
            for(Enumeration e = NetworkInterface.getNetworkInterfaces();e.hasMoreElements() && cont;){
                NetworkInterface inter = (NetworkInterface)e.nextElement();

                for(Enumeration ne = inter.getInetAddresses();ne.hasMoreElements() && cont;){
                    InetAddress add = (InetAddress)ne.nextElement();

                    String name = add.getHostName();
                    String addr   = add.getHostAddress();

                    //SORRY - this should be some regular expression check, but just hacked it out.. 
                    int index = addr.indexOf("."); 
                        index = addr.indexOf(".", index);
                            index = addr.indexOf(".", index);
                                //Check it..
                                    cont = false;
                                    System.out.println("LocalHost found "+name+" "+addr);
                                    //Now set the JCIFS property

This has worked 99%of the time, but on machines that have a pocket PC connected via Active Sync I have noticed that 2 valid IP addresses can be found and only one of them works... Also if you have twin network cards on a single box..

Now I have changed it to :-

        socket = new Socket( thost, port); No Binding at all, and it works fine. Can you explain what the benefit of the binding is ?

3) This one's a little strange and I wish I knew why it works or not... just does.. 

    I was getting a crash (SMB_COM_AND_WRITEX or something..) whenever uploading large files ( 100MB or more ) to my server, after about 20 minutes. I traced the code in debug mode and found out about the /* Dodge NetBIOS keep-alive */ code that you have implemented.

What I found though was that after a certain amount of time, about 20 miutes,

SmbTransport.java line 329

.}while(sbuf[0] == 0x85) was failing EVEN THOUGH sbuf[0] had a value of what seemed like 0x85 !!

I changed it to

}while(((int)sbuf[0]) == -123); Which I AGREE should be EXACTLY THE SAME, but now I no longer get the crash bug. Any Ideas ?

4) I have a 10Mbps connection at home, and the most I have managed to download using the SmbRandomAccessFile is 1Mbps.

At work I have a 24Mbps connection and the most I have managed to get off the server is 320KBps (~3 MBps). Over Apache/HTTP I have got much higher speeds. I looked in the archive and you mention something about Windows not sending the ACK signal fast enough for the MTU or something..? Is that still an issue ? Can something be done about it.  Have I just set it up wrong ?

Thanx for listening, hope this stuff isn't a waste of everyone's time..


ps keep up the excellent work..


-------------- next part --------------
HTML attachment scrubbed and removed

More information about the jcifs mailing list