Package protocolP2P

## Class ProtocolP2PDatagram

- java.lang.Object
- - protocolP2P.ProtocolP2PDatagram

-     public class ProtocolP2PDatagram
      extends java.lang.Object

  Representation of datagram.
  Version:
    1.0
  Author:
    Louis Royer, Flavien Haas, JS Auge

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ProtocolP2PDatagram​(Payload payload)` | Constructor with payload parameter (typically used when sending datagram).

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Payload` | `getPayload()` | Returns Payload associated with the datagram.
    `static ProtocolP2PDatagram` | `receive​(java.net.DatagramSocket socket)` | Receive datagram on socket
    `void` | `send​(java.net.DatagramSocket socket, java.lang.String host, int port)` | Send datagram on socket (from client)
    `void` | `send​(java.net.DatagramSocket socket, ProtocolP2PDatagram received)` | Send datagram on socket (from server, as a response)

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

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

- - ### Constructor Detail

    - #### ProtocolP2PDatagram

          public ProtocolP2PDatagram​(Payload payload)

      Constructor with payload parameter (typically used when sending datagram).
      Parameters:
        `payload` - the payload associated with the datagram to send

  - ### Method Detail

    - #### send

          public void send​(java.net.DatagramSocket socket,
                           java.lang.String host,
                           int port)
                    throws InternalError,
                           java.net.UnknownHostException,
                           java.io.IOException

      Send datagram on socket (from client)
      Parameters:
        `socket` - DatagramSocket used to send datagram.
        `host` - host to send datagram (null if this is a response)
        `port` - port to send datagram (null if this is a response)
      Throws:
        `InternalError`
        `java.net.UnknownHostException`
        `java.io.IOException`

    - #### send

          public void send​(java.net.DatagramSocket socket,
                           ProtocolP2PDatagram received)
                    throws InternalError,
                           java.io.IOException

      Send datagram on socket (from server, as a response)
      Parameters:
        `socket` - DatagramSocket used to send datagram.
        `received` - datagram to respond (aka request)
      Throws:
        `InternalError`
        `java.io.IOException`

    - #### receive

          public static ProtocolP2PDatagram receive​(java.net.DatagramSocket socket)
                                             throws EmptyFile,
                                                    NotFound,
                                                    EmptyDirectory,
                                                    InternalRemoteError,
                                                    VersionRemoteError,
                                                    ProtocolRemoteError,
                                                    TransmissionError,
                                                    ProtocolError,
                                                    VersionError,
                                                    InternalError,
                                                    SizeError,
                                                    java.io.IOException

      Receive datagram on socket
      Parameters:
        `socket` - DatagramSocket used to receive datagram
      Throws:
        `TransmissionError`
        `ProtocolError`
        `VersionError`
        `InternalError`
        `SizeError`
        `ProtocolRemoteError`
        `VersionRemoteError`
        `InternalRemoteError`
        `EmptyDirectory`
        `NotFound`
        `java.io.IOException`
        `EmptyFile`

    - #### getPayload

          public Payload getPayload()

      Returns Payload associated with the datagram.
      Returns:
        payload associated with the datagram