public class ProtocolP2PPacketUDP<T extends Payload> extends ProtocolP2PPacket<T>
| Modifier and Type | Field and Description |
|---|---|
private static int |
CHECKSUM_POSITION |
private HostItem |
remoteHost |
private java.net.DatagramSocket |
requestSocket |
private java.net.DatagramSocket |
responseSocket |
private java.net.SocketAddress |
responseSocketAddress |
payload, version, VERSION_POSITION| Modifier | Constructor and Description |
|---|---|
private |
ProtocolP2PPacketUDP(byte[] packet)
Private constructor with packet as byte[] parameter (typically used when receiving Packet response).
|
|
ProtocolP2PPacketUDP(java.lang.Object socket)
Receive Request (typically used from server).
|
|
ProtocolP2PPacketUDP(T payload)
Constructor with payload parameter (typically used when sending packet).
|
| Modifier and Type | Method and Description |
|---|---|
private void |
checkCheckSum(byte[] packet)
Used to check if the checksum is correct
|
private int |
computeCheckSum(byte[] packet)
Compute checksum associated to packet.
|
private void |
constructPacket(byte[] packet)
Private constructor helper with packet as byte[] parameter (typically used when receiving Packet response/request).
|
private void |
constructPacket(byte[] packet,
java.net.DatagramSocket responseSocket)
Private constructor helper with packet as byte[] parameter and (typically used when receiving Packet request).
|
HostItem |
getHostItem()
Get hostItem of the sender
|
ProtocolP2PPacket<?> |
receiveResponse()
Receive response (typically used by client).
|
protected void |
send(java.net.DatagramSocket socket)
Send a Packet.
|
protected void |
send(java.net.DatagramSocket socket,
java.net.SocketAddress addr)
Send a Packet.
|
void |
sendRequest(java.lang.Object socket)
Send a Request throught socket.
|
<U extends ProtocolP2PPacket<?>> |
sendResponse(U response)
Send a Response to a Request (typically used from server).
|
private void |
setCheckSum(byte[] packet)
Used to set checksum into packet
|
protected byte[] |
toPacket()
Returns a byte[] containing full packet (typically used when sending packet).
|
checkProtocolVersion, getPayloadprivate static final int CHECKSUM_POSITION
private HostItem remoteHost
private java.net.SocketAddress responseSocketAddress
private java.net.DatagramSocket responseSocket
private java.net.DatagramSocket requestSocket
public ProtocolP2PPacketUDP(T payload)
payload - the payload associated with the packet to sendpublic ProtocolP2PPacketUDP(java.lang.Object socket)
throws TransmissionError,
ProtocolError,
VersionError,
InternalError,
SizeError,
java.io.IOException,
SocketClosed
socket - socket used to receive requestTransmissionErrorProtocolErrorVersionErrorInternalErrorSizeErrorjava.io.IOExceptionSocketClosedprivate ProtocolP2PPacketUDP(byte[] packet)
throws TransmissionError,
ProtocolError,
VersionError,
InternalError,
SizeError
packet - the full Packet receivedTransmissionErrorProtocolErrorVersionErrorInternalErrorSizeErrorprotected void send(java.net.DatagramSocket socket)
throws InternalError,
java.io.IOException
socket - DatagramSocket used to send Packet.InternalErrorjava.io.IOExceptionprotected void send(java.net.DatagramSocket socket,
java.net.SocketAddress addr)
throws InternalError,
java.io.IOException
socket - DatagramSocket used to send Packet.addr - SocketAddress used to send Packet.InternalErrorjava.io.IOExceptionpublic void sendRequest(java.lang.Object socket)
throws InternalError,
java.io.IOException
sendRequest in class ProtocolP2PPacket<T extends Payload>socket - DatagramSocket. Must be connected.InternalErrorjava.io.IOExceptionpublic <U extends ProtocolP2PPacket<?>> void sendResponse(U response) throws InternalError, java.io.IOException
sendResponse in class ProtocolP2PPacket<T extends Payload>response - Packet to send as a response.InternalErrorjava.io.IOExceptionpublic ProtocolP2PPacket<?> receiveResponse() throws EmptyFile, NotFound, NotATracker, EmptyDirectory, InternalRemoteError, VersionRemoteError, ProtocolRemoteError, TransmissionError, ProtocolError, VersionError, InternalError, SizeError, java.io.IOException, UnknownHost
receiveResponse in class ProtocolP2PPacket<T extends Payload>EmptyFileNotFoundNotATrackerEmptyDirectoryInternalRemoteErrorVersionRemoteErrorProtocolRemoteErrorTransmissionErrorProtocolErrorVersionErrorInternalErrorSizeErrorjava.io.IOExceptionUnknownHostprivate void constructPacket(byte[] packet)
throws TransmissionError,
ProtocolError,
VersionError,
InternalError,
SizeError
packet - the full Packet receivedTransmissionErrorProtocolErrorVersionErrorInternalErrorSizeErrorprivate void constructPacket(byte[] packet,
java.net.DatagramSocket responseSocket)
throws TransmissionError,
ProtocolError,
VersionError,
InternalError,
SizeError
packet - the full Packet receivedresponseSocket - socket address used to reception this request (use this one to respond)TransmissionErrorProtocolErrorVersionErrorInternalErrorSizeErrorprotected byte[] toPacket()
throws InternalError
InternalErrorprivate int computeCheckSum(byte[] packet)
throws SizeError
packet - the full packet receivedSizeErrorprivate void setCheckSum(byte[] packet)
throws InternalError
packet - full packetInternalErrorprivate void checkCheckSum(byte[] packet)
throws TransmissionError
packet - full packetTransmissionErrorpublic HostItem getHostItem() throws InternalError
getHostItem in class ProtocolP2PPacket<T extends Payload>InternalError