FileDocCategorySizeDatePackage
NbtSocket.javaAPI DocJCIFS 1.3.17 API4999Tue Oct 18 15:26:24 BST 2011jcifs.netbios

NbtSocket

public class NbtSocket extends Socket
Do not use this class. Writing to the OutputStream of this type of socket requires leaving a 4 byte prefix for the NBT header. IOW you must call write( buf, 4, len ). Calling write( buf, 0, len ) will generate an error.

Fields Summary
private static final int
SSN_SRVC_PORT
private static final int
BUFFER_SIZE
private static final int
DEFAULT_SO_TIMEOUT
private static jcifs.util.LogStream
log
private NbtAddress
address
private Name
calledName
private int
soTimeout
Constructors Summary
public NbtSocket()


      
        super();
    
public NbtSocket(NbtAddress address, int port)

        this( address, port, null, 0 );
    
public NbtSocket(NbtAddress address, int port, InetAddress localAddr, int localPort)

        this( address, null, port, localAddr, localPort );
    
public NbtSocket(NbtAddress address, String calledName, int port, InetAddress localAddr, int localPort)

        super( address.getInetAddress(), ( port == 0 ? SSN_SRVC_PORT : port ),
                                localAddr, localPort );
        this.address = address;
        if( calledName == null ) {
            this.calledName = address.hostName;
        } else {
            this.calledName = new Name( calledName, 0x20, null );
        }
        soTimeout = Config.getInt( "jcifs.netbios.soTimeout", DEFAULT_SO_TIMEOUT );
        connect();
    
Methods Summary
public voidclose()

        if( log.level > 3 )
            log.println( "close: " + this );
        super.close();
    
private voidconnect()

        byte[] buffer = new byte[BUFFER_SIZE];
        int type;
        InputStream in;

        try {
            in = super.getInputStream();
            OutputStream out = super.getOutputStream();

            SessionServicePacket ssp0 = new SessionRequestPacket( calledName, NbtAddress.localhost.hostName );
            out.write( buffer, 0, ssp0.writeWireFormat( buffer, 0 ));

            setSoTimeout( soTimeout );
            type = ssp0.readPacketType( in, buffer, 0 );
        } catch( IOException ioe ) {
            close();
            throw ioe;
        }

        switch( type ) {
            case SessionServicePacket.POSITIVE_SESSION_RESPONSE:
                if( log.level > 2 )
                    log.println( "session established ok with " + address );
                return;
            case SessionServicePacket.NEGATIVE_SESSION_RESPONSE:
                int errorCode = (int)( in.read() & 0xFF );
                close();
                throw new NbtException( NbtException.ERR_SSN_SRVC, errorCode );
            case -1:
                throw new NbtException( NbtException.ERR_SSN_SRVC, NbtException.CONNECTION_REFUSED );
            default:
                close();
                throw new NbtException( NbtException.ERR_SSN_SRVC, 0 );
        }
    
public java.io.InputStreamgetInputStream()

        return new SocketInputStream( super.getInputStream() );
    
public java.net.InetAddressgetLocalAddress()

        return super.getLocalAddress();
    
public intgetLocalPort()

        return super.getLocalPort();
    
public NbtAddressgetNbtAddress()

        return address;
    
public java.io.OutputStreamgetOutputStream()

        return new SocketOutputStream( super.getOutputStream() );
    
public intgetPort()

        return super.getPort();
    
public java.lang.StringtoString()

        return "NbtSocket[addr=" + address +
                ",port=" + super.getPort() +
                ",localport=" + super.getLocalPort() + "]";