📄 tcpmon.java
字号:
if ( done && saved == 0 ) { break a; } len1 = -1; break; } } len = len1; if ( len == -1 && saved == 0 ) { break ; } if ( len == -1) { done = true; } // No matter how we may (or may not) format it, send it // on unformatted - we don't want to mess with how its // sent to the other side, just how its displayed if ( out != null && len > 0 ) { slowLink.pump(len); out.write( buffer, saved, len ); } if ( tmodel != null && reqSaved < 50 ) { String old = (String) tmodel.getValueAt( tableIndex, REQ_COLUMN); old = old + new String(buffer, saved, len); if ( old.length() > 50 ) { old = old.substring(0, 50); } reqSaved = old.length(); if ( (i = old.indexOf('\n')) > 0 ) { old = old.substring(0, i - 1); reqSaved = 50 ; } tmodel.setValueAt( old, tableIndex, REQ_COLUMN ); } if ( xmlFormat ) { // Do XML Formatting boolean inXML = false ; int bufferLen = saved ; if ( len != -1 ) { bufferLen += len ; } i1 = 0 ; i2 = 0 ; saved = 0 ; for ( ; i1 < bufferLen ; i1++ ) { // Except when we're at EOF, saved last char if ( len != -1 && i1 + 1 == bufferLen ) { saved = 1; break; } thisIndent = -1; if ( buffer[i1] == '<' && buffer[i1 + 1] != '/' ) { previousIndent = nextIndent++; thisIndent = nextIndent; inXML = true ; } if ( buffer[i1] == '<' && buffer[i1 + 1] == '/' ) { if (previousIndent > nextIndent) { thisIndent = nextIndent; } previousIndent = nextIndent--; inXML = true ; } if ( buffer[i1] == '/' && buffer[i1 + 1] == '>' ) { previousIndent = nextIndent--; inXML = true ; } if ( thisIndent != -1 ) { if ( thisIndent > 0 ) { tmpbuffer[i2++] = (byte) '\n'; } for ( i = tabWidth * thisIndent; i > 0; i-- ) { tmpbuffer[i2++] = (byte) ' '; } } atMargin = ( buffer[i1] == '\n' || buffer[i1] == '\r'); if ( !inXML || !atMargin ) { tmpbuffer[i2++] = buffer[i1]; } } message = new String( tmpbuffer, 0, i2, getEncoding() ); if (numericEnc) { textArea.append( StringUtils.escapeNumericChar(message) ); } else { textArea.append( StringUtils.unescapeNumericChar(message) ); } // Shift saved bytes to the beginning for ( i = 0 ; i < saved ; i++ ) { buffer[i] = buffer[bufferLen - saved + i]; } } else { message = new String( buffer, 0, len, getEncoding() ); if (numericEnc) { textArea.append( StringUtils.escapeNumericChar(message) ); } else { textArea.append( StringUtils.unescapeNumericChar(message) ); } } // this.sleep(3); // Let other threads have a chance to run } // this.sleep(3); // Let other threads have a chance to run // halt(); // Only set the 'done' flag if we were reading from a // Socket - if we were reading from an input stream then // we'll let the other side control when we're done // if ( inSocket != null ) done = true ; } catch ( Throwable t ) { t.printStackTrace(); } finally { done = true ; try { if (out != null) { out.flush(); if (null != outSocket) { outSocket.shutdownOutput(); } else { out.close(); } out = null; } } catch (Exception e) { ; } try { if (in != null) { if (inSocket != null) { inSocket.shutdownInput(); } else { in.close(); } in = null; } } catch (Exception e) { ; } myConnection.wakeUp(); } } private String getEncoding() { try { return XMLUtils.getEncoding(); } catch (Throwable t){ return "UTF-8"; } } public void halt() { try { if ( inSocket != null ) { inSocket.close(); } if ( outSocket != null ) { outSocket.close(); } inSocket = null ; outSocket = null ; if ( in != null ) { in.close(); } if ( out != null ) { out.close(); } in = null ; out = null ; done = true; } catch ( Exception e ) { e.printStackTrace(); } } } /** * a connection listens to a single current connection */ class Connection extends Thread { Listener listener ; boolean active ; String fromHost ; String time ; JTextArea inputText = null ; JScrollPane inputScroll = null ; JTextArea outputText = null ; JScrollPane outputScroll = null ; Socket inSocket = null ; Socket outSocket = null ; Thread clientThread = null ; Thread serverThread = null ; SocketRR rr1 = null ; SocketRR rr2 = null ; InputStream inputStream = null ; String HTTPProxyHost = null ; int HTTPProxyPort = 80 ; private SlowLinkSimulator slowLink; public Connection(Listener l) { listener = l ; HTTPProxyHost = l.HTTPProxyHost ; HTTPProxyPort = l.HTTPProxyPort ; slowLink =l.slowLink; } public Connection(Listener l, Socket s ) { this (l); inSocket = s ; start(); } public Connection(Listener l, InputStream in ) { this (l); inputStream = in ; start(); } public void run() { try { active = true ; HTTPProxyHost = System.getProperty( "http.proxyHost" ); if ( HTTPProxyHost != null && HTTPProxyHost.equals("") ) { HTTPProxyHost = null ; } if ( HTTPProxyHost != null ) { String tmp = System.getProperty( "http.proxyPort" ); if ( tmp != null && tmp.equals("") ) { tmp = null ; } if ( tmp == null ) { HTTPProxyPort = 80 ; } else { HTTPProxyPort = Integer.parseInt( tmp ); } } if ( inSocket != null ) { fromHost = (inSocket.getInetAddress()).getHostName(); } else { fromHost = "resend" ; } String dateformat=getMessage("dateformat00", "yyyy-MM-dd HH:mm:ss"); DateFormat df = new SimpleDateFormat(dateformat); time = df.format( new Date() ); int count = listener.connections.size(); listener.tableModel.insertRow(count + 1, new Object[] { getMessage("active00", "Active"), time, fromHost, listener.hostField.getText(), "" } ); listener.connections.add( this ); inputText = new JTextArea( null, null, 20, 80 ); inputScroll = new JScrollPane( inputText ); outputText = new JTextArea( null, null, 20, 80 ); outputScroll = new JScrollPane( outputText ); ListSelectionModel lsm = listener.connectionTable.getSelectionModel(); if ( count == 0 || lsm.getLeadSelectionIndex() == 0 ) { listener.outPane.setVisible( false ); int divLoc = listener.outPane.getDividerLocation(); listener.setLeft( inputScroll ); listener.setRight( outputScroll ); listener.removeButton.setEnabled(false); listener.removeAllButton.setEnabled(true); listener.saveButton.setEnabled(true); listener.resendButton.setEnabled(true); listener.outPane.setDividerLocation(divLoc); listener.outPane.setVisible( true ); } String targetHost = listener.hostField.getText(); int targetPort = Integer.parseInt(listener.tPortField.getText()); int listenPort = Integer.parseInt(listener.portField.getText()); InputStream tmpIn1 = inputStream ; OutputStream tmpOut1 = null ; InputStream tmpIn2 = null ; OutputStream tmpOut2 = null ; if ( tmpIn1 == null ) { tmpIn1 = inSocket.getInputStream(); } if ( inSocket != null ) { tmpOut1 = inSocket.getOutputStream(); } String bufferedData = null ; StringBuffer buf = null ; int index = listener.connections.indexOf( this ); if (listener.isProxyBox.isSelected() || HTTPProxyHost != null) { // Check if we're a proxy byte[] b = new byte[1]; buf = new StringBuffer(); String s ; for ( ; ; ) { int len ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -