Reads packets from the socket
430562
def __read(self):
        
        # Set the socket as non-blocking
        self._socket.setblocking(0)

        while not self._stop_event.is_set():
            # Watch for content
            ready = select.select([self._socket], [], [], 1)
            if ready[0]:
                # Socket is ready
                data, sender = self._socket.recvfrom(1024)
                try:
                    self._handle_heartbeat(sender, data)
                except Exception as ex:
                    _logger.exception("Error handling the heart beat: %s", ex)
1236672
def decode_network_packet(buf):
    
    off = 0
    blen = len(buf)

    while off < blen:
        ptype, plen = header.unpack_from(buf, off)

        if plen > blen - off:
            raise ValueError("Packet longer than amount of data in buffer")

        if ptype not in _decoders:
            raise ValueError("Message type %i not recognized" % ptype)

        yield ptype, _decoders[ptype](ptype, plen, buf[off:])
        off += plen
344886
def _sense_packet_to_data(packet):
        """"""
        data = bytearray(0)
        last = 0
        i = 1
        while (i < len(packet)):
            if not (last == 2 and packet[i] == 0):
                data.append(packet[i])
            last = packet[i]
            i += 1

        return data
263037
def read_whole_packet(self):
        
        self._read_packet()
        return readall(self, self._size - _header.size)
892581
def _get_packet(self, socket):
        
        data, (ip, port) = socket.recvfrom(self._buffer_size)
        packet, remainder = self._unpack(data)
        self.inbox.put((ip, port, packet))
        self.new_packet.set()
        self.debug(u"RX: {}".format(packet))

        if packet.header.sequence_number is not None:
            # Packet needs to be acknowledged
            self._send_ack(ip, port, packet)
        ack_seq = packet.header.ack_sequence_number
        if ack_seq is not None:
            # Packet got acknowledged
            with self._seq_ack_lock:
                if ack_seq in self._seq_ack:
                    self.debug(u"Seq {} got acked".format(ack_seq))
                    self._seq_ack.remove(ack_seq)
        return packet
108767
def socket_read(fp):
    
    response = ''
    oldlen = 0
    newlen = 0
    while True:
        response += fp.read(buffSize)
        newlen = len(response)
        if newlen - oldlen == 0:
            break
        else:
            oldlen = newlen
    return response
1340919
def read_all(socket)
      total_bytes = socket.recv(4).unpack("V")[0]
      if total_bytes and total_bytes > 0
        socket.recv(total_bytes)
      else
        ''
      end
    end
543894
def socket_reader(connection: socket, buffer_size: int = 1024):
    
    while connection is not None:
        try:
            buffer = connection.recv(buffer_size)
            # no output
            if not len(buffer):
                raise ConnectionAbortedError
        except ConnectionAbortedError:
            # socket closed
            print('connection aborted')
            connection.close()
            yield None
        except OSError:
            # still operate connection after it was closed
            print('socket closed')
            connection.close()
            yield None
        else:
            yield buffer
242624
private static List<ResponsePacket> readResponses(Socket socket) {
		List<ResponsePacket> responses = new Vector<ResponsePacket>();
		int previousTimeout = 0;
		try {
			/* Set socket timeout to avoid getting stuck on read() */
			try {
				previousTimeout = socket.getSoTimeout();
				socket.setSoTimeout(TIMEOUT);
			} catch (Exception e) {
			}
			InputStream input = socket.getInputStream();
			while (true) {
				ResponsePacket packet = readResponsePacketData(input);
				if (packet != null) responses.add(packet);
				else break;
			}

		} catch (Exception e) {
			/* Ignore exception, as we are expecting timeout exceptions because Apple might not reply anything */
			//System.out.println(e);
		}
		/* Reset socket timeout, just in case */
		try {
			socket.setSoTimeout(previousTimeout);
		} catch (Exception e) {
		}
		//System.out.println("Received "+responses.size()+" response packets");
		return responses;
	}
480451
def receive_data(socket):
    
    answer = b""
    while True:
        packet = socket.recv(4096)
        if not packet: break
        answer += packet
    response = pickle.loads(answer)
    socket.close()
    return response
1189811
def _read_data(self):
        
        while True:
            try:
                data = yield from self._socket.recv()
            except asyncio.CancelledError:
                break
            except ConnectionClosed:
                break

            self._push_packet(data)

        self._loop.call_soon(self.close)
46767
def capture_packet(self):
        '''  '''
        data = self.socket.recv(self._buffer_size)

        for h in self.capture_handlers:
            h['reads'] += 1
            h['data_read'] += len(data)

            d = data
            if 'pre_write_transforms' in h:
                for data_transform in h['pre_write_transforms']:
                    d = data_transform(d)
            h['logger'].write(d)
591856
private void receive() {
    try {
      Socket socket = null;
      BufferedReader reader = null;
      try {
        // connect to the server
        socket = new Socket(host, port);
        reader = new BufferedReader(
            new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
        // Until stopped or connection broken continue reading
        String userInput;
        while (!isStopped() && (userInput = reader.readLine()) != null) {
          System.out.println("Received data '" + userInput + "'");
          store(userInput);
        }
      } finally {
        Closeables.close(reader, /* swallowIOException = */ true);
        Closeables.close(socket,  /* swallowIOException = */ true);
      }
      // Restart in an attempt to connect again when server is active again
      restart("Trying to connect again");
    } catch(ConnectException ce) {
      // restart if could not connect to server
      restart("Could not connect", ce);
    } catch(Throwable t) {
      restart("Error receiving data", t);
    }
  }
490021
private void recv(byte[] buffer, int length) throws IOException {
    int bytes = 0;

    while (bytes < length) {
      int res = socket.getInputStream().read(buffer, bytes, length - bytes);
      if (res > 0) {
        bytes += res;
      } else {
        return;
      }
    }
  }
1334922
def receive(socket, num_bytes=20):
    
    length = int(_receive_all(socket, num_bytes).decode())
    serialized_data = _receive_all(socket, length)
    return pickle.loads(serialized_data)
642603
def read_frame(self):
        
        header = Header.decode_header(self.stream)
        if header.flags:
            raise WebSocketError
        if not header.length:
            return header, ''
        try:
            payload = self.stream.read(header.length)
        except socket_error:
            payload = ''
        except Exception:
            logger.debug("{}: {}".format(type(e), six.text_type(e)))
            payload = ''
        if len(payload) != header.length:
            raise WebSocketError('Unexpected EOF reading frame payload')
        if header.mask:
            payload = header.unmask_payload(payload)
        return header, payload
1321489
def _read(self):
        
        line = ''
        finished = False
        while not finished:
            char = self._socket.recv(1)
            if char == '':
                return ''
            elif char == '\r':
                continue
            elif char == '\n':
                finished = True
                continue
            else:
                line = line + char
        logger.debug('Server sent: ' + line.rstrip())
        return line