public static void sendData(SelectionKey key, Object dataObj) {
		byte[] data = null;
		byte[] lengthPacket = null;
		
		try {
			//serialize the data to be sent
			data = NetworkPacketManager.serialize(dataObj);
			
			//compute the length of the package
			lengthPacket = NetworkPacketManager.packetLength(data);
			
		} catch (IOException e) {
			loggerServer.error("Error serializing object");
			e.printStackTrace();
		}
		
		loggerServer.info("To write " + data.length + 
				" bytes on the socket associated with the key " + key);
	
		ArrayList<byte[]> wbuf = null;
		
		synchronized (key) {
			wbuf = writeBuffers.get(key);
			if (wbuf == null) {
				wbuf = new ArrayList<byte[]>();
				writeBuffers.put(key, wbuf);
			}
			wbuf.add(lengthPacket);
			wbuf.add(data);
			if (key != null)
				key.interestOps(SelectionKey.OP_WRITE);
		}
				
		selector.wakeup();
	}