protected void writeChannel(SocketChannel channel) {
// If there is a packet to send.
if (!packetQueue.isEmpty()) {
// Get the packet from the queue.
Packet packetToSend;
packetToSend = packetQueue.poll();
try {
// Write the packet content to the channel.
channel.write(packetToSend.getByteBuffer());
} catch (IOException e) {
// If there is an IO Exception we assumed the connection died
// and we try to reconnect.
reconnect();
}