Source Code Cross Referenced for SQLProxy.java in  » Database-JDBC-Connection-Pool » jTDS » net » sourceforge » jtds » tools » 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 » Database JDBC Connection Pool » jTDS » net.sourceforge.jtds.tools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.jtds.tools;
002:
003:        import java.io.*;
004:        import java.net.*;
005:
006:        public class SQLProxy {
007:            static final int LOCAL_PORT = 1433;
008:
009:            static final String SERVER = "server";
010:            static final int SERVER_PORT = 1433;
011:
012:            public static void main(String args[]) throws IOException {
013:                ServerSocket sock = new ServerSocket(LOCAL_PORT);
014:                while (true) {
015:                    Socket s = sock.accept();
016:                    new DumpThread(s).start();
017:                }
018:            }
019:        }
020:
021:        class DumpThread extends Thread {
022:            private Socket client, server;
023:            private byte[] buf = new byte[4096];
024:
025:            DumpThread(Socket client) {
026:                this .client = client;
027:            }
028:
029:            String hex(int value, int len) {
030:                String res = Integer.toHexString(value);
031:                while (res.length() < len)
032:                    res = '0' + res;
033:                return res.toUpperCase();
034:            }
035:
036:            String packetType(int value) {
037:                switch (value) {
038:                case 0x01:
039:                    return "4.2 or 7.0 query";
040:                case 0x02:
041:                    return "4.2 or 7.0 login packet";
042:                case 0x04:
043:                    return "Server response";
044:                case 0x06:
045:                    return "Cancel";
046:                case 0x0F:
047:                    return "5.0 query";
048:                case 0x10:
049:                    return "7.0 login packet";
050:                default:
051:                    return "Unknown (0x" + hex(value, 2) + ')';
052:                }
053:            }
054:
055:            int passByte(InputStream in, OutputStream out) throws IOException {
056:                int res = in.read();
057:                out.write(res);
058:                return res;
059:            }
060:
061:            void skip(int len, InputStream in, OutputStream out)
062:                    throws IOException {
063:                while (len > 0) {
064:                    int rd = in.read(buf, 0, len > buf.length ? buf.length
065:                            : len);
066:                    //            for( int i=0; i<rd; i++ )
067:                    //                System.out.print((char)buf[i]);
068:                    //            System.out.println();
069:                    //            for( int i=0; i<rd; i++ )
070:                    //                System.out.print(hex(((int)buf[i])&0xFF, 2)+" ");
071:                    //            System.out.println();
072:                    out.write(buf, 0, rd);
073:                    len -= rd;
074:                }
075:            }
076:
077:            boolean nextPacket(InputStream in, OutputStream out)
078:                    throws IOException {
079:                int type = passByte(in, out), last = passByte(in, out);
080:
081:                int size = passByte(in, out) << 8 | passByte(in, out);
082:
083:                buf[0] = (byte) passByte(in, out);
084:                buf[1] = (byte) passByte(in, out);
085:                buf[2] = (byte) passByte(in, out);
086:                buf[3] = (byte) passByte(in, out);
087:
088:                System.out.println("Packet type: " + packetType(type));
089:                System.out.println("Packet size: " + size + " (0x"
090:                        + hex(size, 4) + ")");
091:                System.out.print("Rest of header:");
092:                for (int i = 0; i < 4; i++)
093:                    System.out.print(" 0x" + hex(((int) buf[i]) & 0xFF, 2));
094:                System.out.println();
095:
096:                skip(size - 8, in, out);
097:
098:                return last == 0;
099:            }
100:
101:            public void run() {
102:                try {
103:                    server = new Socket(SQLProxy.SERVER, SQLProxy.SERVER_PORT);
104:
105:                    InputStream cIn = client.getInputStream();
106:                    OutputStream cOut = client.getOutputStream();
107:                    InputStream sIn = server.getInputStream();
108:                    OutputStream sOut = server.getOutputStream();
109:
110:                    while (true) {
111:                        while (nextPacket(cIn, sOut))
112:                            ;
113:                        System.out.println("--- Client done. ---\n");
114:                        while (nextPacket(sIn, cOut))
115:                            ;
116:                        System.out.println("--- Server done. ---\n");
117:                    }
118:                } catch (IOException ex) {
119:                    try {
120:                        client.close();
121:                    } catch (IOException exc) {
122:                    }
123:                    try {
124:                        server.close();
125:                    } catch (IOException exc) {
126:                    }
127:                    System.out.println("Disconnected.");
128:                }
129:            }
130:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.