edu.internet2.ndt

## Class Protocol

- java.lang.Object
- - edu.internet2.ndt.Protocol

-     public class Protocol
      extends Object

  Class aggregating operations that can be performed for sending/receiving/reading Protocol messages

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Protocol(Socket ctlSocketParam)` Constructor that accepts socket over which to communicate as parameter

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Method to close open Streams
    `int` | `readn(Message msgParam, int iParamAmount)` Populate Message byte array with specific number of bytes of data from socket input stream
    `int` | `recv_msg(Message msgParam)` Receive message at end-point of socket
    `void` | `send_json_login_msg(byte bParamType, byte[] bParamToSend)` Send protocol messages given their type and data byte array
    `void` | `send_json_msg(byte bParamType, byte bParamToSend)` Send message given its Type and data byte
    `void` | `send_json_msg(byte bParamType, byte[] bParamToSend)` Send protocol messages given their type and data byte array
    `void` | `send_msg(byte bParamType, byte bParamToSend)` Send message given its Type and data byte
    `void` | `send_msg(byte bParamType, byte[] bParamToSend)` Send protocol messages given their type and data byte array
    `void` | `setJsonSupport(boolean jsonSupport)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Protocol

          public Protocol(Socket ctlSocketParam)
                   throws IOException

      Constructor that accepts socket over which to communicate as parameter
      Parameters:
        `ctlSocketParam` - socket used to send the protocol messages over
      Throws:
        `IOException` - if Input/Output streams cannot be read from/written into correctly

  - ### Method Detail

    - #### close

          public void close()

      Method to close open Streams

    - #### readn

          public int readn(Message msgParam,
                           int iParamAmount)
                    throws IOException

      Populate Message byte array with specific number of bytes of data from socket input stream
      Parameters:
        `msgParam` - Message object to be populated
        `iParamAmount` - specified number of bytes to be read
      Returns:
        integer number of bytes populated
      Throws:
        `IOException` - If data cannot be successfully read from the Input Stream

    - #### recv_msg

          public int recv_msg(Message msgParam)
                       throws IOException

      Receive message at end-point of socket
      Parameters:
        `msgParam` - Message object
      Returns:
        integer with values:

        a) Success:

        - value=0 : successfully read expected number of bytes.

        b) Error:

        - value= 1 : Error reading ctrl-message length and data type itself, since NDTP-control packet has to be at the least 3 octets long
        - value= 3 : Error, mismatch between "length" field of ctrl-message and actual data read
      Throws:
        `IOException`

    - #### send_json_login_msg

          public void send_json_login_msg(byte bParamType,
                                          byte[] bParamToSend)
                                   throws IOException

      Send protocol messages given their type and data byte array
      Parameters:
        `bParamType` - Control Message Type
        `bParamToSend` - Data value array to send
      Throws:
        `IOException` - If data cannot be successfully written to the Output Stream

    - #### send_json_msg

          public void send_json_msg(byte bParamType,
                                    byte bParamToSend)
                             throws IOException

      Send message given its Type and data byte
      Parameters:
        `bParamType` - Control Message Type
        `bParamToSend` - Data value to send
      Throws:
        `IOException` - If data cannot be successfully written to the Output Stream

    - #### send_json_msg

          public void send_json_msg(byte bParamType,
                                    byte[] bParamToSend)
                             throws IOException

      Send protocol messages given their type and data byte array
      Parameters:
        `bParamType` - Control Message Type
        `bParamToSend` - Data value array to send
      Throws:
        `IOException` - If data cannot be successfully written to the Output Stream

    - #### send_msg

          public void send_msg(byte bParamType,
                               byte bParamToSend)
                        throws IOException

      Send message given its Type and data byte
      Parameters:
        `bParamType` - Control Message Type
        `bParamToSend` - Data value to send
      Throws:
        `IOException` - If data cannot be successfully written to the Output Stream

    - #### send_msg

          public void send_msg(byte bParamType,
                               byte[] bParamToSend)
                        throws IOException

      Send protocol messages given their type and data byte array
      Parameters:
        `bParamType` - Control Message Type
        `bParamToSend` - Data value array to send
      Throws:
        `IOException` - If data cannot be successfully written to the Output Stream

    - #### setJsonSupport

          public void setJsonSupport(boolean jsonSupport)