Source Code Cross Referenced for SocketChannel.java in  » Scripting » jacl » tcl » lang » 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 » Scripting » jacl » tcl.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SocketChannel.java
003:         *
004:         * Implements a socket channel.
005:         */
006:        package tcl.lang;
007:
008:        import java.io.*;
009:        import java.net.Socket;
010:        import java.net.InetAddress;
011:        import java.net.UnknownHostException;
012:
013:        /**
014:         * The SocketChannel class implements a channel object for Socket
015:         * connections, created using the socket command.
016:         **/
017:
018:        public class SocketChannel extends Channel {
019:
020:            /**
021:             * The java Socket object associated with this Channel
022:             **/
023:
024:            private Socket sock;
025:
026:            /**
027:             * Constructor - creates a new SocketChannel object with the given
028:             * options. Also creates an underlying Socket object, and Input and
029:             * Output Streams.
030:             **/
031:
032:            public SocketChannel(Interp interp, int mode, String localAddr,
033:                    int localPort, boolean async, String address, int port)
034:                    throws IOException, TclException {
035:                InetAddress localAddress = null;
036:                InetAddress addr = null;
037:
038:                if (async)
039:                    throw new TclException(interp,
040:                            "Asynchronous socket connection not "
041:                                    + "currently implemented");
042:
043:                // Resolve addresses
044:                if (!localAddr.equals("")) {
045:                    try {
046:                        localAddress = InetAddress.getByName(localAddr);
047:                    } catch (UnknownHostException e) {
048:                        throw new TclException(interp, "host unknown: "
049:                                + localAddr);
050:                    }
051:                }
052:
053:                try {
054:                    addr = InetAddress.getByName(address);
055:                } catch (UnknownHostException e) {
056:                    throw new TclException(interp, "host unknown: " + address);
057:                }
058:
059:                // Set the mode of this socket.
060:                this .mode = mode;
061:
062:                // Create the Socket object
063:
064:                if ((localAddress != null) && (localPort != 0))
065:                    sock = new Socket(addr, port, localAddress, localPort);
066:                else
067:                    sock = new Socket(addr, port);
068:
069:                // If we got this far, then the socket has been created.
070:                // Create the channel name
071:                setChanName(TclIO.getNextDescriptor(interp, "sock"));
072:            }
073:
074:            /**
075:             * Constructor for making SocketChannel objects from connections
076:             * made to a ServerSocket.
077:             **/
078:
079:            public SocketChannel(Interp interp, Socket s) throws IOException,
080:                    TclException {
081:                this .mode = TclIO.RDWR;
082:                this .sock = s;
083:
084:                setChanName(TclIO.getNextDescriptor(interp, "sock"));
085:            }
086:
087:            /**
088:             * Close the SocketChannel.
089:             */
090:
091:            void close() throws IOException {
092:                // Invoke super.close() first since it might write an eof char
093:                try {
094:                    super .close();
095:                } finally {
096:                    sock.close();
097:                }
098:            }
099:
100:            String getChanType() {
101:                return "tcp";
102:            }
103:
104:            protected InputStream getInputStream() throws IOException {
105:                return sock.getInputStream();
106:            }
107:
108:            protected OutputStream getOutputStream() throws IOException {
109:                return sock.getOutputStream();
110:            }
111:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.