View Javadoc

1   /*
2    * Copyright 2000 Computer System Services, Inc.
3    *
4    * Permission to use this software for any purpose is granted provided that
5    * this copyright notice is preserved.
6    *
7    * This software is provided as-is and without warranty as to its
8    * fitness for any purpose.  In other words, Computer System Services,
9    * Inc. does not guarantee that this software works.  It is provided
10   * only in the hope that it may be found useful by someone.
11   *
12   * Please e-mail tttaylor@cssassociates.com if you find any errors
13   * or want to request changes/enhancements.
14   */
15  package twcsckernel.projectbase.rmi.socketfactory;
16  
17  /***
18   * Constants and utilities for the two-way signalling protocol.
19   *
20   * @author Tim Taylor  -- tttaylor@cssassociates.com
21   */
22  public class TwoWay {
23      /***
24       * Opcodes for protocol.
25       */
26      /*** Header for all messages in the protocol */
27      public static final int PROTOCOL_MAGIC = 23861;
28      
29      /***
30       * Sent by client to register the signalling channel socket with
31       * the server.
32       */
33      public static final int REGISTER_CALLBACK_SOCKET_SOURCE = 0;
34      
35      /***
36       * Sent by the client to tell the server that the socket
37       * is a callback socket for the server's use in calling
38       * client callbacks.
39       */
40      public static final int RETURN_CALLBACK_SOCKET = 1;
41  
42      /***
43       * Sent by the server to the client to request that the
44       * client make a callback socket for the server's use.
45       */
46      public static final int REQUEST_CALLBACK_SOCKET = 2;
47  
48      /***
49       * Sent by the server to the client to inform the client
50       * of the server address.  This is the actually address
51       * from the server's viewpoint and will be different
52       * from the address used to connect to the server if
53       * forwarding through a firewall.
54       */
55      public static final int RETURN_SERVER_ENDPOINT_INFO = 3;
56  
57      /***
58       * Maximum length of messages in the protocol.
59       */
60      public static final int MAX_MESSAGE_LENGTH = 50;
61  
62      /*** String names of opcodes.  Used for debugging. */
63      private static final String[] opcodeNames = {
64          "REGISTER_CALLBACK_SOCKET_SOURCE",
65          "RETURN_CALLBACK_SOCKET",
66          "REQUEST_CALLBACK_SOCKET",
67          "RETURN_SERVER_ENDPOINT_INFO"
68      };
69  
70      /***
71       * Utility method to convert an IP address to a string.
72       *
73       * @param address The four bytes of an IP address.
74       * @return The corresponding string (a.b.c.d format).
75       */
76      public static String getAddressString(byte[] address) {
77          return ((int) address[0] &0xff) + "." +
78              ((int) address[1] & 0xff) + "." +
79              ((int) address[2] & 0xff) + "." +
80              ((int) address[3] & 0xff);
81      }
82  
83      public static String getOpcodeName(int opcode) {
84          return opcodeNames[opcode];
85      }
86  }