def serve(io)
      while not stopped?
        header = io.read(7)
        tx_id = header[0,2]
        proto_id = header[2,2]
        len = header[4,2].unpack('n')[0]
        unit_id = header.getbyte(6)
        if proto_id == "\x00\x00"
          req = io.read(len - 1)
          if unit_id == @uid || unit_id == 0
            log "Server RX (#{req.size} bytes): #{logging_bytes(req)}"

            pdu = exec_req(req, @coils, @discrete_inputs, @holding_registers, @input_registers)

            resp = tx_id + "\0\0" + (pdu.size + 1).to_word + @uid.chr + pdu
            log "Server TX (#{resp.size} bytes): #{logging_bytes(resp)}"
            io.write resp
          else
            log "Ignored server RX (invalid unit ID #{unit_id}, #{req.size} bytes): #{logging_bytes(req)}"
          end
        end
      end
    end
def serve(io)
      while not stopped?
        header = io.read(7)
        tx_id = header[0,2]
        proto_id = header[2,2]
        len = header[4,2].unpack('n')[0]
        unit_id = header.getbyte(6)
        if proto_id == "\x00\x00"
          req = io.read(len - 1)
          if unit_id == @uid || unit_id == 0
            log "Server RX (#{req.size} bytes): #{logging_bytes(req)}"

            pdu = exec_req(req, @coils, @discrete_inputs, @holding_registers, @input_registers)

            resp = tx_id + "\0\0" + (pdu.size + 1).to_word + @uid.chr + pdu
            log "Server TX (#{resp.size} bytes): #{logging_bytes(resp)}"
            io.write resp
          else
            log "Ignored server RX (invalid unit ID #{unit_id}, #{req.size} bytes): #{logging_bytes(req)}"
          end
        end
      end
    end
Init server
 @param [Integer] port listen port
 @param [Integer] uid slave device
 @param [Hash] opts options of server
 @option opts [String] :host host of server default '127.0.0.1'
 @option opts [Float, Integer] :max_connection max of TCP connection with server default 4
 Serve requests
 @param [TCPSocket] io socket