Source Code Cross Referenced for CharGenUDPClient.java in  » Net » Apache-commons-net-1.4.1 » org » apache » commons » net » 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 » Net » Apache commons net 1.4.1 » org.apache.commons.net 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2005 The Apache Software Foundation
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.commons.net;
017:
018:        import java.io.IOException;
019:        import java.net.DatagramPacket;
020:        import java.net.InetAddress;
021:
022:        /***
023:         * The CharGenUDPClient class is a UDP implementation of a client for the
024:         * character generator protocol described in RFC 864.  It can also be
025:         * used for Systat (RFC 866), Quote of the Day (RFC 865), and netstat
026:         * (port 15).  All of these protocols involve sending a datagram to the
027:         * appropriate port, and reading data contained in one or more reply
028:         * datagrams.  The chargen and quote of the day protocols only send
029:         * one reply datagram containing 512 bytes or less of data.  The other
030:         * protocols may reply with more than one datagram, in which case you
031:         * must wait for a timeout to determine that all reply datagrams have
032:         * been sent.
033:         * <p>
034:         * To use the CharGenUDPClient class, just open a local UDP port
035:         * with {@link org.apache.commons.net.DatagramSocketClient#open  open }
036:         * and call {@link #send  send } to send the datagram that will
037:         * initiate the data reply.  For chargen or quote of the day, just
038:         * call {@link #receive  receive }, and you're done.  For netstat and
039:         * systat, call receive in a while loop, and catch a SocketException and
040:         * InterruptedIOException to detect a timeout (don't forget to set the
041:         * timeout duration beforehand).  Don't forget to call
042:         * {@link org.apache.commons.net.DatagramSocketClient#close  close() }
043:         * to clean up properly.
044:         * <p>
045:         * <p>
046:         * @author Daniel F. Savarese
047:         * @see CharGenTCPClient
048:         ***/
049:
050:        public final class CharGenUDPClient extends DatagramSocketClient {
051:            /*** The systat port value of 11 according to RFC 866. ***/
052:            public static final int SYSTAT_PORT = 11;
053:            /*** The netstat port value of 19. ***/
054:            public static final int NETSTAT_PORT = 15;
055:            /*** The quote of the day port value of 17 according to RFC 865. ***/
056:            public static final int QUOTE_OF_DAY_PORT = 17;
057:            /*** The character generator port value of 19 according to RFC 864. ***/
058:            public static final int CHARGEN_PORT = 19;
059:            /*** The default chargen port.  It is set to 19 according to RFC 864. ***/
060:            public static final int DEFAULT_PORT = 19;
061:
062:            private byte[] __receiveData;
063:            private DatagramPacket __receivePacket;
064:            private DatagramPacket __sendPacket;
065:
066:            /***
067:             * The default CharGenUDPClient constructor.  It initializes some internal
068:             * data structures for sending and receiving the necessary datagrams for
069:             * the chargen and related protocols.
070:             ***/
071:            public CharGenUDPClient() {
072:                // CharGen return packets have a maximum length of 512
073:                __receiveData = new byte[512];
074:                __receivePacket = new DatagramPacket(__receiveData, 512);
075:                __sendPacket = new DatagramPacket(new byte[0], 0);
076:            }
077:
078:            /***
079:             * Sends the data initiation datagram.  This data in the packet is ignored
080:             * by the server, and merely serves to signal that the server should send
081:             * its reply.
082:             * <p>
083:             * @param host The address of the server.
084:             * @param port The port of the service.
085:             * @exception IOException If an error occurs while sending the datagram.
086:             ***/
087:            public void send(InetAddress host, int port) throws IOException {
088:                __sendPacket.setAddress(host);
089:                __sendPacket.setPort(port);
090:                _socket_.send(__sendPacket);
091:            }
092:
093:            /*** Same as <code>send(host, CharGenUDPClient.DEFAULT_PORT);</code> ***/
094:            public void send(InetAddress host) throws IOException {
095:                send(host, DEFAULT_PORT);
096:            }
097:
098:            /***
099:             * Receive the reply data from the server.  This will always be 512 bytes
100:             * or less.  Chargen and quote of the day only return one packet.  Netstat
101:             * and systat require multiple calls to receive() with timeout detection.
102:             * <p>
103:             * @return The reply data from the server.
104:             * @exception IOException If an error occurs while receiving the datagram.
105:             ***/
106:            public byte[] receive() throws IOException {
107:                int length;
108:                byte[] result;
109:
110:                _socket_.receive(__receivePacket);
111:
112:                result = new byte[length = __receivePacket.getLength()];
113:                System.arraycopy(__receiveData, 0, result, 0, length);
114:
115:                return result;
116:            }
117:
118:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.