@Override
	public void run() {
		//System.err.println("going!");
		try {
			client = new Socket(targetIP, port); //open connection
			InputStream reader = client.getInputStream();
			byte[] headerBuff = new byte[4];
			byte[] buff = null;
			boolean header = true;
			int dataLength = 0;
			while (client.isConnected()) {
				if (header && reader.available() >= 4) { //if header and at least 4 bytes available parse header (header is 4 bytes)
					header = false;
					reader.read(headerBuff);
					dataLength = headerToInt(headerBuff);
					//System.out.println("Found " + dataLength / 7 + " APs!");
				} else if (!header && reader.available() >= dataLength) { //if !header and complete message is available, parse message
					buff = new byte[dataLength];
					reader.read(buff);
					data.add(bytesToMACandRSSI(buff)); //Add the MacRssiPair[] to the shared queue
					header = true;
				}
				Thread.sleep(100);
			}
			System.out.println("Connection to server lost...");

		} catch (SocketException e) {
			System.err.println("Could not reach the WLANScanner :(");

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}