public class ProtocolP2PPacketTCP<T extends Payload> extends ProtocolP2PPacket<T>
Modifier and Type | Field and Description |
---|---|
private java.net.Socket |
requestSocket |
private java.net.Socket |
responseSocket |
payload, version, VERSION_POSITION
Modifier | Constructor and Description |
---|---|
private |
ProtocolP2PPacketTCP(byte[] packet)
Private constructor with packet as byte[] parameter (typically used when receiving Packet response).
|
|
ProtocolP2PPacketTCP(java.lang.Object socket)
Receive Request (typically used from server).
|
|
ProtocolP2PPacketTCP(T payload)
Constructor with payload parameter (typically used when sending packet).
|
Modifier and Type | Method and Description |
---|---|
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.Socket 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.Socket socket)
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).
|
protected byte[] |
toPacket()
Returns a byte[] containing full packet (typically used when sending packet).
|
checkProtocolVersion, getPayload
private java.net.Socket responseSocket
private java.net.Socket requestSocket
public ProtocolP2PPacketTCP(T payload)
payload
- the payload associated with the packet to sendpublic ProtocolP2PPacketTCP(java.lang.Object socket) throws TransmissionError, ProtocolError, VersionError, InternalError, SizeError, SocketClosed, java.io.IOException
socket
- socket used to receive requestTransmissionError
ProtocolError
VersionError
InternalError
SizeError
SocketClosed
java.io.IOException
private ProtocolP2PPacketTCP(byte[] packet) throws TransmissionError, ProtocolError, VersionError, InternalError, SizeError
packet
- the full Packet receivedTransmissionError
ProtocolError
VersionError
InternalError
SizeError
protected void send(java.net.Socket socket) throws InternalError, SocketClosed, java.io.IOException
socket
- Socket used to send Packet.InternalError
SocketClosed
java.io.IOException
public void sendRequest(java.lang.Object socket) throws InternalError, java.io.IOException, SocketClosed
sendRequest
in class ProtocolP2PPacket<T extends Payload>
socket
- Socket. Must be connected.InternalError
SocketClosed
java.io.IOException
public <U extends ProtocolP2PPacket<?>> void sendResponse(U response) throws InternalError, java.io.IOException, SocketClosed
sendResponse
in class ProtocolP2PPacket<T extends Payload>
response
- Packet to send as a response.InternalError
java.io.IOException
SocketClosed
public ProtocolP2PPacket<?> receiveResponse() throws EmptyFile, NotFound, NotATracker, EmptyDirectory, InternalRemoteError, VersionRemoteError, ProtocolRemoteError, TransmissionError, ProtocolError, VersionError, InternalError, SizeError, java.io.IOException, SocketClosed, UnknownHost
receiveResponse
in class ProtocolP2PPacket<T extends Payload>
EmptyFile
NotFound
NotATracker
EmptyDirectory
InternalRemoteError
VersionRemoteError
ProtocolRemoteError
TransmissionError
ProtocolError
VersionError
InternalError
SizeError
java.io.IOException
SocketClosed
UnknownHost
private void constructPacket(byte[] packet) throws TransmissionError, ProtocolError, VersionError, InternalError, SizeError
packet
- the full Packet receivedTransmissionError
ProtocolError
VersionError
InternalError
SizeError
private void constructPacket(byte[] packet, java.net.Socket responseSocket) throws TransmissionError, ProtocolError, VersionError, InternalError, SizeError
packet
- the full Packet receivedresponseSocket
- socket address used to reception this request (use this one to respond)TransmissionError
ProtocolError
VersionError
InternalError
SizeError
protected byte[] toPacket() throws InternalError
InternalError
public HostItem getHostItem() throws InternalError
getHostItem
in class ProtocolP2PPacket<T extends Payload>
InternalError