Thread: [Beepcore-java-commits] CVS: beepcore-java/example/org/beepcore/beep/example Bing.java,1.2,1.3
Status: Beta
Brought to you by:
huston
|
From: Huston F. <hu...@us...> - 2001-07-29 03:57:41
|
Update of /cvsroot/beepcore-java/beepcore-java/example/org/beepcore/beep/example
In directory usw-pr-cvs1:/tmp/cvs-serv32415/example/org/beepcore/beep/example
Modified Files:
Bing.java
Log Message:
Added session close on errors
Index: Bing.java
===================================================================
RCS file: /cvsroot/beepcore-java/beepcore-java/example/org/beepcore/beep/example/Bing.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** Bing.java 2001/07/11 02:46:19 1.2
--- Bing.java 2001/07/29 03:57:39 1.3
***************
*** 69,160 ****
}
! // Start TLS if requested
! if (privacy != PRIVACY_NONE) {
! try {
! session =
! TLSProfile.getDefaultInstance().startTLS((TCPSession) session);
! } catch (BEEPException e) {
! System.err.println("bing: Error unable to start TLS.\n\t" +
! e.getMessage());
! if (privacy == PRIVACY_REQUIRED)
! return;
}
- }
! // Start a channel for the echo profile
! Channel channel;
! try {
! channel = session.startChannel(EchoProfile.ECHO_URI);
! } catch (BEEPError e) {
! if (e.getCode() == 550) {
! System.err.println("bing: Error host does not support echo " +
! "profile");
! } else {
System.err.println("bing: Error starting channel (" +
! e.getCode() + ": " + e.getMessage() + ")");
}
- return;
- } catch (BEEPException e) {
- System.err.println("bing: Error starting channel (" +
- e.getMessage() + ")");
- return;
- }
! String request = createRequest(size);
! try {
! for (int i=0; i<count; ++i) {
! long time;
! int replyLength = 0;
! Reply reply = new Reply();
!
! time = System.currentTimeMillis();
!
! // Send the request
! channel.sendMSG(new StringDataStream(request), reply);
!
! // Get the reply to the request
! DataStream ds = reply.getNextReply().getDataStream();
! InputStream is = ds.getInputStream();
!
! // Read the data in the reply
! while (ds.isComplete() == false || is.available() > 0) {
! is.read();
! ++replyLength;
}
!
! System.out.println("Reply from " + host + ": bytes=" +
! replyLength + " time=" +
! (System.currentTimeMillis() - time) +
! "ms");
}
- } catch (BEEPError e) {
- System.err.println("bing: Error sending request (" + e.getCode() +
- ": " + e.getMessage() + ")");
- return;
- } catch (Exception e) {
- System.err.println("bing: Error sending request (" +
- e.getMessage() + ")");
- return;
- }
! // Cleanup
! // Close the Channel
! try {
! channel.close();
! } catch (BEEPException e) {
! System.err.println("bing: Error closing channel (" +
! e.getMessage() + ")");
! return;
! }
! // Close the Session
! try {
! session.close();
! } catch (BEEPException e) {
! System.err.print("bing: Error closing session (" +
! e.getMessage() + ")");
! return;
}
}
--- 69,163 ----
}
! try {
! // Start TLS if requested
! if (privacy != PRIVACY_NONE) {
! try {
! session =
! TLSProfile.getDefaultInstance().startTLS((TCPSession) session);
! } catch (BEEPException e) {
! System.err.println("bing: Error unable to start TLS.\n\t" +
! e.getMessage());
! if (privacy == PRIVACY_REQUIRED)
! return;
! }
}
! // Start a channel for the echo profile
! Channel channel;
! try {
! channel = session.startChannel(EchoProfile.ECHO_URI);
! } catch (BEEPError e) {
! if (e.getCode() == 550) {
! System.err.println("bing: Error host does not support echo " +
! "profile");
! } else {
! System.err.println("bing: Error starting channel (" +
! e.getCode() + ": " + e.getMessage() + ")");
! }
! return;
! } catch (BEEPException e) {
System.err.println("bing: Error starting channel (" +
! e.getMessage() + ")");
! return;
}
! String request = createRequest(size);
! try {
! for (int i=0; i<count; ++i) {
! long time;
! int replyLength = 0;
! Reply reply = new Reply();
!
! time = System.currentTimeMillis();
!
! // Send the request
! channel.sendMSG(new StringDataStream(request), reply);
!
! // Get the reply to the request
! DataStream ds = reply.getNextReply().getDataStream();
! InputStream is = ds.getInputStream();
!
! // Read the data in the reply
! while (ds.isComplete() == false || is.available() > 0) {
! is.read();
! ++replyLength;
! }
!
! System.out.println("Reply from " + host + ": bytes=" +
! replyLength + " time=" +
! (System.currentTimeMillis() - time) +
! "ms");
}
! } catch (BEEPError e) {
! System.err.println("bing: Error sending request (" + e.getCode() +
! ": " + e.getMessage() + ")");
! return;
! } catch (Exception e) {
! System.err.println("bing: Error sending request (" +
! e.getMessage() + ")");
! return;
}
! // Cleanup
! // Close the Channel
! try {
! channel.close();
! } catch (BEEPException e) {
! System.err.println("bing: Error closing channel (" +
! e.getMessage() + ")");
! return;
! }
! } finally {
! // Close the Session
! try {
! session.close();
! } catch (BEEPException e) {
! System.err.print("bing: Error closing session (" +
! e.getMessage() + ")");
! return;
! }
}
}
|