Source Code Cross Referenced for NbtSocket.java in  » Groupware » hipergate » com » knowgate » jcifs » netbios » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Groupware » hipergate » com.knowgate.jcifs.netbios 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* jcifs smb client library in Java
002:         * Copyright (C) 2000  "Michael B. Allen" <jcifs at samba dot org>
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:
019:        package com.knowgate.jcifs.netbios;
020:
021:        import java.net.Socket;
022:        import java.net.InetAddress;
023:        import java.io.InputStream;
024:        import java.io.OutputStream;
025:        import java.io.IOException;
026:
027:        import com.knowgate.debug.DebugFile;
028:        import com.knowgate.jcifs.Config;
029:
030:        /**
031:         Do not use this class. Writing to the OutputStream of this type of socket
032:         requires leaving a 4 byte prefix for the NBT header. IOW you must call
033:         write( buf, 4, len ). Calling write( buf, 0, len ) will generate an error.
034:         */
035:
036:        public class NbtSocket extends Socket {
037:
038:            private static final int SSN_SRVC_PORT = 139;
039:            private static final int BUFFER_SIZE = 512;
040:            private static final int DEFAULT_SO_TIMEOUT = 5000;
041:
042:            private NbtAddress address;
043:            private Name calledName;
044:            private int soTimeout;
045:
046:            public NbtSocket() {
047:                super ();
048:            }
049:
050:            public NbtSocket(NbtAddress address, int port) throws IOException {
051:                this (address, port, null, 0);
052:            }
053:
054:            public NbtSocket(NbtAddress address, int port,
055:                    InetAddress localAddr, int localPort) throws IOException {
056:                this (address, null, port, localAddr, localPort);
057:            }
058:
059:            public NbtSocket(NbtAddress address, String calledName, int port,
060:                    InetAddress localAddr, int localPort) throws IOException {
061:                super (address.getInetAddress(), (port == 0 ? SSN_SRVC_PORT
062:                        : port), localAddr, localPort);
063:                this .address = address;
064:                if (calledName == null) {
065:                    this .calledName = address.hostName;
066:                } else {
067:                    this .calledName = new Name(calledName, 0x20, null);
068:                }
069:                soTimeout = Config.getInt("jcifs.netbios.soTimeout",
070:                        DEFAULT_SO_TIMEOUT);
071:                connect();
072:            }
073:
074:            public NbtAddress getNbtAddress() {
075:                return address;
076:            }
077:
078:            public InputStream getInputStream() throws IOException {
079:                return new SocketInputStream(super .getInputStream());
080:            }
081:
082:            public OutputStream getOutputStream() throws IOException {
083:                return new SocketOutputStream(super .getOutputStream());
084:            }
085:
086:            public int getPort() {
087:                return super .getPort();
088:            }
089:
090:            public InetAddress getLocalAddress() {
091:                return super .getLocalAddress();
092:            }
093:
094:            public int getLocalPort() {
095:                return super .getLocalPort();
096:            }
097:
098:            public String toString() {
099:                return "NbtSocket[addr=" + address + ",port=" + super .getPort()
100:                        + ",localport=" + super .getLocalPort() + "]";
101:            }
102:
103:            private void connect() throws IOException {
104:                byte[] buffer = new byte[BUFFER_SIZE];
105:                int type;
106:                InputStream in;
107:
108:                try {
109:                    in = super .getInputStream();
110:                    OutputStream out = super .getOutputStream();
111:
112:                    SessionServicePacket ssp0 = new SessionRequestPacket(
113:                            calledName, NbtAddress.localhost.hostName);
114:                    out.write(buffer, 0, ssp0.writeWireFormat(buffer, 0));
115:
116:                    setSoTimeout(soTimeout);
117:                    type = ssp0.readPacketType(in, buffer, 0);
118:                } catch (IOException ioe) {
119:                    close();
120:                    throw ioe;
121:                }
122:
123:                switch (type) {
124:                case SessionServicePacket.POSITIVE_SESSION_RESPONSE:
125:                    if (DebugFile.trace)
126:                        DebugFile.writeln("session established ok with "
127:                                + address);
128:                    return;
129:                case SessionServicePacket.NEGATIVE_SESSION_RESPONSE:
130:                    int errorCode = (int) (in.read() & 0xFF);
131:                    close();
132:                    throw new NbtException(NbtException.ERR_SSN_SRVC, errorCode);
133:                case -1:
134:                    throw new NbtException(NbtException.ERR_SSN_SRVC,
135:                            NbtException.CONNECTION_REFUSED);
136:                default:
137:                    close();
138:                    throw new NbtException(NbtException.ERR_SSN_SRVC, 0);
139:                }
140:            }
141:
142:            public void close() throws IOException {
143:                if (DebugFile.trace)
144:                    DebugFile.writeln("close: " + this);
145:                super.close();
146:            }
147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.